mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use duck typing to also allow MemCache-like object when initializing a MemCacheStore
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
parent
d8fffe7b23
commit
36058f4504
3 changed files with 8 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
*Edge*
|
*Edge*
|
||||||
|
|
||||||
* Allow MemCacheStore to be initialized with a MemCache object instead of addresses and options [Bryan Helmkamp]
|
* Allow MemCacheStore to be initialized with a MemCache-like object instead of addresses and options [Bryan Helmkamp]
|
||||||
|
|
||||||
* Change spelling of Kyev timezone to Kyiv #2613 [Alexander Dymo]
|
* Change spelling of Kyev timezone to Kyiv #2613 [Alexander Dymo]
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ module ActiveSupport
|
||||||
# If no addresses are specified, then MemCacheStore will connect to
|
# If no addresses are specified, then MemCacheStore will connect to
|
||||||
# localhost port 11211 (the default memcached port).
|
# localhost port 11211 (the default memcached port).
|
||||||
def initialize(*addresses)
|
def initialize(*addresses)
|
||||||
if addresses.first.is_a?(MemCache)
|
if addresses.first.respond_to?(:get)
|
||||||
@data = addresses.first
|
@data = addresses.first
|
||||||
else
|
else
|
||||||
@data = self.class.build_mem_cache(*addresses)
|
@data = self.class.build_mem_cache(*addresses)
|
||||||
|
|
|
@ -27,6 +27,12 @@ class CacheStoreSettingTest < ActiveSupport::TestCase
|
||||||
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
|
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_mem_cache_fragment_cache_store_with_given_mem_cache_like_object
|
||||||
|
MemCache.expects(:new).never
|
||||||
|
store = ActiveSupport::Cache.lookup_store :mem_cache_store, stub("memcache", :get => true)
|
||||||
|
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
|
||||||
|
end
|
||||||
|
|
||||||
def test_mem_cache_fragment_cache_store_with_multiple_servers
|
def test_mem_cache_fragment_cache_store_with_multiple_servers
|
||||||
MemCache.expects(:new).with(%w[localhost 192.168.1.1], {})
|
MemCache.expects(:new).with(%w[localhost 192.168.1.1], {})
|
||||||
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1'
|
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1'
|
||||||
|
|
Loading…
Reference in a new issue