diff options
author | Arthur Neves <arthurnn@gmail.com> | 2014-01-03 16:39:50 -0500 |
---|---|---|
committer | Arthur Neves <arthurnn@gmail.com> | 2014-01-03 16:39:50 -0500 |
commit | e7f56a7fe8fbb10e62a18b836c27aa1a0f7c5464 (patch) | |
tree | f48c4a899b1b669cfafd89ef3c2588f0a6b543f0 | |
parent | 98458eea425d15ebadf366d8b55fc89c1913d146 (diff) | |
download | rails-e7f56a7fe8fbb10e62a18b836c27aa1a0f7c5464.tar.gz rails-e7f56a7fe8fbb10e62a18b836c27aa1a0f7c5464.tar.bz2 rails-e7f56a7fe8fbb10e62a18b836c27aa1a0f7c5464.zip |
Raise if MemCacheStore doenst receive a Dalli obj
:mem_cache_store should receive a list of hosts or a dalli client,
otherwise raise it.
Also adding a changelog.
-rw-r--r-- | activesupport/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/cache/mem_cache_store.rb | 3 | ||||
-rw-r--r-- | activesupport/test/caching_test.rb | 8 |
3 files changed, 15 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 19db8ac873..973eaef471 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,7 @@ +* MemCacheStore should only accept a Dalli::Client, or create one. + + *arthurnn* + * Don't lazy load the `tzinfo` library as it causes problems on Windows. Fixes #13553 diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index 1ac4819d47..0eacc4c078 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -46,6 +46,9 @@ module ActiveSupport options = addresses.extract_options! super(options) + unless [String, Dalli::Client, NilClass].include?(addresses.first.class) + raise ArgumentError, "First argument must be an empty array, an array of hosts or a Dalli::Client instance." + end if addresses.first.is_a?(Dalli::Client) @data = addresses.first else diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 09781f3e7a..7fd76ddf8b 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -110,6 +110,14 @@ class CacheStoreSettingTest < ActiveSupport::TestCase assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) end + def test_mem_cache_fragment_cache_store_with_not_dalli_client + Dalli::Client.expects(:new).never + memcache = Object.new + assert_raises(ArgumentError) do + ActiveSupport::Cache.lookup_store :mem_cache_store, memcache + end + end + def test_mem_cache_fragment_cache_store_with_multiple_servers Dalli::Client.expects(:new).with(%w[localhost 192.168.1.1], {}) store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1' |