2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2017-06-10 04:07:40 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "active_support/cache"
|
|
|
|
|
|
|
|
class CacheStoreLoggerTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@cache = ActiveSupport::Cache.lookup_store(:memory_store)
|
|
|
|
|
|
|
|
@buffer = StringIO.new
|
|
|
|
@cache.logger = ActiveSupport::Logger.new(@buffer)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_logging
|
|
|
|
@cache.fetch("foo") { "bar" }
|
2018-01-25 18:14:09 -05:00
|
|
|
assert_predicate @buffer.string, :present?
|
2017-06-10 04:07:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_log_with_string_namespace
|
|
|
|
@cache.fetch("foo", namespace: "string_namespace") { "bar" }
|
|
|
|
assert_match %r{string_namespace:foo}, @buffer.string
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_log_with_proc_namespace
|
|
|
|
proc = Proc.new do
|
|
|
|
"proc_namespace"
|
|
|
|
end
|
|
|
|
@cache.fetch("foo", namespace: proc) { "bar" }
|
|
|
|
assert_match %r{proc_namespace:foo}, @buffer.string
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_mute_logging
|
|
|
|
@cache.mute { @cache.fetch("foo") { "bar" } }
|
2018-01-25 18:14:09 -05:00
|
|
|
assert_predicate @buffer.string, :blank?
|
2017-06-10 04:07:40 -04:00
|
|
|
end
|
|
|
|
end
|