From e8102910bff143be269d9a6707068a9e5b357370 Mon Sep 17 00:00:00 2001 From: Gonzalo Rodriguez Date: Tue, 23 Jan 2018 15:07:24 -0300 Subject: [PATCH 1/2] Fixes warning 'DEPRECATED: Use assert_nil if expecting nil from ...' --- spec/fail2ban_spec.rb | 2 +- spec/integration/rack_attack_cache_spec.rb | 4 ++-- spec/rack_attack_throttle_spec.rb | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/fail2ban_spec.rb b/spec/fail2ban_spec.rb index 0f24524..adbdb0e 100644 --- a/spec/fail2ban_spec.rb +++ b/spec/fail2ban_spec.rb @@ -73,7 +73,7 @@ describe 'Rack::Attack.Fail2Ban' do it 'resets fail count' do key = "rack::attack:#{Time.now.to_i/@findtime}:fail2ban:count:1.2.3.4" - @cache.store.read(key).must_equal nil + assert_nil @cache.store.read(key) end it 'IP is not banned' do diff --git a/spec/integration/rack_attack_cache_spec.rb b/spec/integration/rack_attack_cache_spec.rb index 6eb27ef..d2001ea 100644 --- a/spec/integration/rack_attack_cache_spec.rb +++ b/spec/integration/rack_attack_cache_spec.rb @@ -92,7 +92,7 @@ describe Rack::Attack::Cache do store.write(@key, "foobar", :expires_in => @expires_in) @cache.read('cache-test-key').must_equal "foobar" store.delete(@key) - @cache.read('cache-test-key').must_equal nil + assert_nil @cache.read('cache-test-key') end end @@ -113,7 +113,7 @@ describe Rack::Attack::Cache do period_key, _ = @cache.send(:key_and_expiry, 'cache-test-key', period) store.read(period_key).to_i.must_equal 1 @cache.reset_count(unprefixed_key, period) - store.read(period_key).must_equal nil + assert_nil store.read(period_key) end end end diff --git a/spec/rack_attack_throttle_spec.rb b/spec/rack_attack_throttle_spec.rb index d64a27d..394102e 100644 --- a/spec/rack_attack_throttle_spec.rb +++ b/spec/rack_attack_throttle_spec.rb @@ -99,11 +99,11 @@ describe 'Rack::Attack.throttle with block retuning nil' do before { get '/', {}, 'REMOTE_ADDR' => '1.2.3.4' } it 'should not set the counter' do key = "rack::attack:#{Time.now.to_i/@period}:ip/sec:1.2.3.4" - Rack::Attack.cache.store.read(key).must_equal nil + assert_nil Rack::Attack.cache.store.read(key) end it 'should not populate throttle data' do - last_request.env['rack.attack.throttle_data'].must_equal nil + assert_nil last_request.env['rack.attack.throttle_data'] end end -end \ No newline at end of file +end From 218a320a3ddc508487071dfe45f18a1780976241 Mon Sep 17 00:00:00 2001 From: Gonzalo Rodriguez Date: Tue, 23 Jan 2018 16:54:13 -0300 Subject: [PATCH 2/2] Fixes warning instead of hiding it Warning was: 'warning: instance variable @data not initialized' --- Rakefile | 1 - lib/rack/attack/store_proxy.rb | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 5f7e9e0..300ec21 100644 --- a/Rakefile +++ b/Rakefile @@ -10,7 +10,6 @@ namespace :test do Rake::TestTask.new(:integration) do |t| t.pattern = "spec/integration/*_spec.rb" - t.warning = false end end diff --git a/lib/rack/attack/store_proxy.rb b/lib/rack/attack/store_proxy.rb index 4d69853..de0bc0c 100644 --- a/lib/rack/attack/store_proxy.rb +++ b/lib/rack/attack/store_proxy.rb @@ -20,7 +20,10 @@ module Rack # We also want to use the underlying Dalli client instead of ::ActiveSupport::Cache::MemCacheStore, # and the MemCache client if using Rails 3.x - client = store.instance_variable_get(:@data) + if store.instance_variable_defined?(:@data) + client = store.instance_variable_get(:@data) + end + if ACTIVE_SUPPORT_WRAPPER_CLASSES.include?(store.class.to_s) && ACTIVE_SUPPORT_CLIENTS.include?(client.class.to_s) client else