diff --git a/lib/rack/attack/store_proxy.rb b/lib/rack/attack/store_proxy.rb index 4b9a6c0..177a3c3 100644 --- a/lib/rack/attack/store_proxy.rb +++ b/lib/rack/attack/store_proxy.rb @@ -66,6 +66,7 @@ module Rack class DalliProxy < SimpleDelegator def initialize(client) super(client) + stub_with_method_on_older_clients end def read(key) @@ -95,6 +96,16 @@ module Rack end rescue Dalli::DalliError end + + private + + # So we support Dalli < 2.7.0 + def stub_with_method_on_older_clients + unless __getobj__.respond_to?(:with) + def __getobj__.with; yield self; end + end + end + end end end diff --git a/spec/integration/rack_attack_cache_spec.rb b/spec/integration/rack_attack_cache_spec.rb index 5ea2201..a39bd5d 100644 --- a/spec/integration/rack_attack_cache_spec.rb +++ b/spec/integration/rack_attack_cache_spec.rb @@ -143,4 +143,11 @@ describe Rack::Attack::Cache do end end + describe "given an older Dalli::Client" do + it "should stub #with" do + proxy = Rack::Attack::StoreProxy::DalliProxy.new(Class.new) + proxy.must_respond_to :with + end + end + end