1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activesupport/test/cache/cache_store_namespace_test.rb
Jeremy Daer ddea316425
Split up the cache test suite so it's easier to understand and extend (#29404)
Split up the caching tests as prep for adding a new cache store. Slices
the mega test/caching_test.rb into behavior modules, concrete store
tests, and cross-cutting store tests.

Considering moving cache store behavior modules into lib/ so they may be
used for acceptance testing by third parties.
2017-06-10 01:23:10 -07:00

38 lines
1.2 KiB
Ruby

require "abstract_unit"
require "active_support/cache"
class CacheStoreNamespaceTest < ActiveSupport::TestCase
def test_static_namespace
cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: "tester")
cache.write("foo", "bar")
assert_equal "bar", cache.read("foo")
assert_equal "bar", cache.instance_variable_get(:@data)["tester:foo"].value
end
def test_proc_namespace
test_val = "tester"
proc = lambda { test_val }
cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: proc)
cache.write("foo", "bar")
assert_equal "bar", cache.read("foo")
assert_equal "bar", cache.instance_variable_get(:@data)["tester:foo"].value
end
def test_delete_matched_key_start
cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: "tester")
cache.write("foo", "bar")
cache.write("fu", "baz")
cache.delete_matched(/^fo/)
assert !cache.exist?("foo")
assert cache.exist?("fu")
end
def test_delete_matched_key
cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: "foo")
cache.write("foo", "bar")
cache.write("fu", "baz")
cache.delete_matched(/OO/i)
assert !cache.exist?("foo")
assert cache.exist?("fu")
end
end