test/cache_test.rb in object-cache-0.0.1 vs test/cache_test.rb in object-cache-0.0.2
- old
+ new
@@ -4,13 +4,14 @@
require 'mock_redis'
require 'object/cache'
require 'minitest/autorun'
# :no-doc:
-class CacheTest < Minitest::Test
+class CacheTest < Minitest::Test # rubocop:disable Metrics/ClassLength
def setup
Cache.backend = MockRedis.new
+ Cache.default_ttl = 604_800
end
def redis
Cache.primary
end
@@ -75,13 +76,19 @@
assert_equal(-1, redis.ttl(redis.keys.first))
end
def test_cache_default_ttl
Cache.new { 'hello world' }
- assert_equal Cache::DEFAULT_TTL, redis.ttl(redis.keys.first)
+ assert_equal Cache.default_ttl, redis.ttl(redis.keys.first)
end
+ def test_cache_custom_default_ttl
+ Cache.default_ttl = 60
+ Cache.new { 'hello world' }
+ assert_equal 60, redis.ttl(redis.keys.first)
+ end
+
def test_cache_with_ttl
Cache.new(ttl: 60) { 'hello world' }
assert_equal 60, redis.ttl(redis.keys.first)
end
@@ -93,9 +100,22 @@
def test_core_extension_options
load 'object/cache/core_extension.rb'
cache(ttl: 60) { 'hello world' }
assert_equal 60, redis.ttl(redis.keys.first)
+ assert Object.send(:remove_method, :cache)
+ end
+
+ def test_core_extension_on_objects
+ load 'object/cache/core_extension.rb'
+ assert_equal 'hello world', 'hello world'.cache
+ assert Object.send(:remove_method, :cache)
+ end
+
+ def test_core_extension_on_objects_with_arguments
+ load 'object/cache/core_extension.rb'
+ 'hello world'.cache(ttl: 30)
+ assert_equal 30, redis.ttl(redis.keys.first)
assert Object.send(:remove_method, :cache)
end
def test_backend_with_replicas
Cache.backend = { primary: redis, replicas: [redis, redis] }