mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Stub #with on delegator
This commit is contained in:
parent
0640a53cdf
commit
f0a53f474e
2 changed files with 6 additions and 5 deletions
|
|
@ -66,7 +66,7 @@ module Rack
|
|||
class DalliProxy < SimpleDelegator
|
||||
def initialize(client)
|
||||
super(client)
|
||||
stub_with_method_on_older_clients
|
||||
stub_with_method_if_missing
|
||||
end
|
||||
|
||||
def read(key)
|
||||
|
|
@ -99,10 +99,11 @@ module Rack
|
|||
|
||||
private
|
||||
|
||||
# So we support Dalli < 2.7.0
|
||||
def stub_with_method_on_older_clients
|
||||
def stub_with_method_if_missing
|
||||
unless __getobj__.respond_to?(:with)
|
||||
def __getobj__.with; yield self; end
|
||||
class << self
|
||||
def with; yield __getobj__; end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ describe Rack::Attack::Cache do
|
|||
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
|
||||
proxy.with {} # will not raise an error
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue