diff options
-rw-r--r-- | activesupport/test/abstract_unit.rb | 10 | ||||
-rw-r--r-- | activesupport/test/caching_test.rb | 88 |
2 files changed, 50 insertions, 48 deletions
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index 34c9e920bc..8a67b148c3 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -21,15 +21,5 @@ require 'empty_bool' ENV['NO_RELOAD'] = '1' require 'active_support' -def uses_memcached(test_name) - require 'dalli' - begin - Dalli::Client.new('localhost:11211').stats - yield - rescue Dalli::DalliError - $stderr.puts "Skipping #{test_name} tests. Start memcached and try again." - end -end - # Show backtraces for deprecated behavior for quicker cleanup. ActiveSupport::Deprecation.debug = true diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 5056d8deb8..71cd9d81b3 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -704,53 +704,65 @@ class MemoryStoreTest < ActiveSupport::TestCase end end -uses_memcached 'memcached backed store' do - class MemCacheStoreTest < ActiveSupport::TestCase - def setup - @cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :expires_in => 60) - @peek = ActiveSupport::Cache.lookup_store(:mem_cache_store) - @data = @cache.instance_variable_get(:@data) - @cache.clear - @cache.silence! - @cache.logger = ActiveSupport::Logger.new("/dev/null") - end +class MemCacheStoreTest < ActiveSupport::TestCase + require 'dalli' + + begin + ss = Dalli::Client.new('localhost:11211').stats + raise Dalli::DalliError unless ss['localhost:11211'] + + MEMCACHE_UP = true + rescue Dalli::DalliError + $stderr.puts "Skipping memcached tests. Start memcached and try again." + MEMCACHE_UP = false + end + + def setup + skip "memcache server is not up" unless MEMCACHE_UP + + @cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :expires_in => 60) + @peek = ActiveSupport::Cache.lookup_store(:mem_cache_store) + @data = @cache.instance_variable_get(:@data) + @cache.clear + @cache.silence! + @cache.logger = ActiveSupport::Logger.new("/dev/null") + end + + include CacheStoreBehavior + include LocalCacheBehavior + include CacheIncrementDecrementBehavior + include EncodedKeyCacheBehavior + + def test_raw_values + cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) + cache.clear + cache.write("foo", 2) + assert_equal "2", cache.read("foo") + end - include CacheStoreBehavior - include LocalCacheBehavior - include CacheIncrementDecrementBehavior - include EncodedKeyCacheBehavior + def test_raw_values_with_marshal + cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) + cache.clear + cache.write("foo", Marshal.dump([])) + assert_equal [], cache.read("foo") + end - def test_raw_values - cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) - cache.clear + def test_local_cache_raw_values + cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) + cache.clear + cache.with_local_cache do cache.write("foo", 2) assert_equal "2", cache.read("foo") end + end - def test_raw_values_with_marshal - cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) - cache.clear + def test_local_cache_raw_values_with_marshal + cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) + cache.clear + cache.with_local_cache do cache.write("foo", Marshal.dump([])) assert_equal [], cache.read("foo") end - - def test_local_cache_raw_values - cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) - cache.clear - cache.with_local_cache do - cache.write("foo", 2) - assert_equal "2", cache.read("foo") - end - end - - def test_local_cache_raw_values_with_marshal - cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) - cache.clear - cache.with_local_cache do - cache.write("foo", Marshal.dump([])) - assert_equal [], cache.read("foo") - end - end end end |