Commit 15f83c86 authored by Quang-Minh Nguyen's avatar Quang-Minh Nguyen

Fix ruby2 keyword argument warnings in rack attack tests

Issue https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/751
parent 69bf9241
...@@ -9,22 +9,20 @@ RSpec.describe Gitlab::RackAttack::InstrumentedCacheStore do ...@@ -9,22 +9,20 @@ RSpec.describe Gitlab::RackAttack::InstrumentedCacheStore do
subject { described_class.new(upstream_store: store)} subject { described_class.new(upstream_store: store)}
where(:operation, :params) do where(:operation, :params, :test_proc) do
:fetch | [:key] :fetch | [:key] | ->(s) { s.fetch(:key) }
:fetch | [:key] :read | [:key] | ->(s) { s.read(:key) }
:read | [:key] :read_multi | [:key_1, :key_2, :key_3] | ->(s) { s.read_multi(:key_1, :key_2, :key_3) }
:read | [:key] :write_multi | [{ key_1: 1, key_2: 2, key_3: 3 }] | ->(s) { s.write_multi(key_1: 1, key_2: 2, key_3: 3) }
:read_multi | [:key_1, :key_2, :key_3] :fetch_multi | [:key_1, :key_2, :key_3] | ->(s) { s.fetch_multi(:key_1, :key_2, :key_3) {} }
:write_multi | [{ key_1: 1, key_2: 2, key_3: 3 }] :write | [:key, :value, { option_1: 1 }] | ->(s) { s.write(:key, :value, option_1: 1) }
:fetch_multi | [:key_1, :key_2, :key_3] :delete | [:key] | ->(s) { s.delete(:key) }
:write | [:key, :value, { option_1: 1 }] :exist? | [:key, { option_1: 1 }] | ->(s) { s.exist?(:key, option_1: 1) }
:delete | [:key] :delete_matched | [/^key$/, { option_1: 1 }] | ->(s) { s.delete_matched(/^key$/, option_1: 1 ) }
:exist? | [:key, { option_1: 1 }] :increment | [:key, 1] | ->(s) { s.increment(:key, 1) }
:delete_matched | [/^key$/, { option_1: 1 }] :decrement | [:key, 1] | ->(s) { s.decrement(:key, 1) }
:increment | [:key, 1] :cleanup | [] | ->(s) { s.cleanup }
:decrement | [:key, 1] :clear | [] | ->(s) { s.clear }
:cleanup | []
:clear | []
end end
with_them do with_them do
...@@ -36,7 +34,7 @@ RSpec.describe Gitlab::RackAttack::InstrumentedCacheStore do ...@@ -36,7 +34,7 @@ RSpec.describe Gitlab::RackAttack::InstrumentedCacheStore do
event = ActiveSupport::Notifications::Event.new(*args) event = ActiveSupport::Notifications::Event.new(*args)
end end
subject.send(operation, *params) {} test_proc.call(subject)
ensure ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end end
...@@ -59,7 +57,7 @@ RSpec.describe Gitlab::RackAttack::InstrumentedCacheStore do ...@@ -59,7 +57,7 @@ RSpec.describe Gitlab::RackAttack::InstrumentedCacheStore do
end end
begin begin
subject.send(operation, *params) {} test_proc.call(subject)
rescue => e rescue => e
exception = e exception = e
end end
...@@ -77,13 +75,15 @@ RSpec.describe Gitlab::RackAttack::InstrumentedCacheStore do ...@@ -77,13 +75,15 @@ RSpec.describe Gitlab::RackAttack::InstrumentedCacheStore do
end end
it 'delegates to the upstream store' do it 'delegates to the upstream store' do
allow(store).to receive(operation).and_call_original
if params.empty? if params.empty?
expect(store).to receive(operation).with(no_args) expect(store).to receive(operation).with(no_args)
else else
expect(store).to receive(operation).with(*params) expect(store).to receive(operation).with(*params)
end end
subject.send(operation, *params) test_proc.call(subject)
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment