Skip to content

Commit

Permalink
build: Reduce to support ruby ​​2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
OuYangJinTing committed Nov 5, 2020
1 parent e0bd429 commit 90498b0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
9 changes: 8 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require:
# - rubocop-packaging
- rubocop-performance
- rubocop-minitest
# - rubocop-packaging

Metrics/BlockLength:
Enabled: false
Expand All @@ -14,5 +15,11 @@ Lint/NestedMethodDefinition:
Layout/RescueEnsureAlignment:
Enabled: false

Layout/LineLength:
Max: 120

Style/DoubleNegation:
Enabled: false

Gemspec/OrderedDependencies:
Enabled: false
8 changes: 5 additions & 3 deletions grape-throttling.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
spec.description = 'Grape rate limit exceeded.'
spec.homepage = 'https://github.com/OuYangJinTing/grape-throttling'
spec.license = 'MIT'
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')

# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"

Expand All @@ -37,7 +37,9 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rack-test'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'minitest-reporters'
spec.add_development_dependency 'rubocop'
# The higher rubocop do not support ruby-2.3
spec.add_development_dependency 'rubocop', '~> 0.81.0'
spec.add_development_dependency 'rubocop-performance', '~> 1.6.1'
spec.add_development_dependency 'rubocop-minitest'
# spec.add_development_dependency 'rubocop-packaging'
spec.add_development_dependency 'rubocop-performance'
end
2 changes: 1 addition & 1 deletion lib/grape/throttling/extension/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Api # :nodoc:

module ClassMethods # :nodoc:
# rubocop:disable Style/ClassVars
def use_throttle(max: 60, expire: 1.day, condition: proc { true }, identity: proc { request.ip }) # rubocop:disable Metrics/MethodLength
def use_throttle(max: 60, expire: 1.day, condition: proc { true }, identity: proc { request.ip }) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
max = max.try(:to_i).to_i
raise ArgumentError, 'max must be positive number' unless max.positive?
raise ArgumentError, 'condition must be Proc' unless condition.is_a?(Proc)
Expand Down
8 changes: 4 additions & 4 deletions test/grape/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ module Grape
let(:request) { Request.allocate }

it '#enabled_throttle' do
assert request.respond_to?(:enabled_throttle)
assert_respond_to request, :enabled_throttle
end

it '#enabled_throttle=' do
assert request.respond_to?(:enabled_throttle=)
assert_respond_to request, :enabled_throttle=
end

it '#id_throttle' do
assert request.respond_to?(:id_throttle)
assert_respond_to request, :id_throttle
end

it '#id_throttle=' do
assert request.respond_to?(:id_throttle=)
assert_respond_to request, :id_throttle=
end

it '#throttle?' do
Expand Down
2 changes: 1 addition & 1 deletion test/grape/throttling/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Throttling
let(:config) { Configuration.new }

it '#redis' do
assert config.respond_to?(:redis)
assert_respond_to config, :redis
end

it '#redis=' do
Expand Down
12 changes: 6 additions & 6 deletions test/grape/throttling/counter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ module Throttling
after { counter.del(key) }

it '#set' do
assert counter.respond_to?(:set)
assert_respond_to counter, :set
end

it '#del' do
assert counter.respond_to?(:del)
assert_respond_to counter, :del
end

it '#expire' do
assert counter.respond_to?(:expire)
assert_respond_to counter, :expire
end

it '#ttl' do
assert counter.respond_to?(:ttl)
assert_respond_to counter, :ttl
end

describe '#get' do
Expand All @@ -45,9 +45,9 @@ module Throttling

it 'should not set expire when key already exists' do
counter.incr(key)
assert counter.incr(key) != 1
refute_equal counter.incr(key), 1
sleep 1
assert counter.ttl(key) != expire
refute_equal counter.ttl(key), expire
end

it 'should success call even if redis store value type error' do
Expand Down

0 comments on commit 90498b0

Please sign in to comment.