blob: 1af6893cc93c76c37f1c3388bebfae4edbddffa4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# frozen_string_literal: true
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" }
assert @buffer.string.present?
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" } }
assert @buffer.string.blank?
end
end
|