33# Released under the MIT License.
44# Copyright, 2023-2026, by Samuel Williams.
55# Copyright, 2024, by Michael Adams.
6+ # Copyright, 2026, by Yasha Krasnou.
67
78require "app"
89require "console/capture"
@@ -21,6 +22,54 @@ def before
2122 expect ( Rails . logger ) . to be ( :respond_to? , :tagged )
2223 end
2324
25+ it "should log tags that are Hashes" do
26+ Rails . logger . tagged ( { foo : "bar" } ) do
27+ Rails . logger . info ( "Hello World" )
28+ end
29+
30+ expect ( capture . last ) . to have_keys (
31+ message : be == "Hello World" ,
32+ foo : be == "bar"
33+ )
34+ end
35+
36+ it "should not fail when logging string tags" do
37+ Rails . logger . tagged ( "foo=bar" ) do
38+ Rails . logger . info ( "Hello World" )
39+ end
40+
41+ expect ( capture . last ) . to have_keys (
42+ message : be == "Hello World"
43+ )
44+
45+ expect ( capture . last ) . not . to have_keys ( :foo )
46+ expect ( capture . last ) . not . to have_keys ( "foo=bar" )
47+ end
48+
49+ it "should symbolize string-keyed hash tags" do
50+ Rails . logger . tagged ( { "request_id" => "abc" } ) do
51+ Rails . logger . info ( "Hello World" )
52+ end
53+
54+ expect ( capture . last ) . to have_keys (
55+ message : be == "Hello World" ,
56+ request_id : be == "abc"
57+ )
58+ expect ( capture . last ) . not . to have_keys ( "request_id" )
59+ end
60+
61+ it "should symbolize HashWithIndifferentAccess tags" do
62+ Rails . logger . tagged ( ActiveSupport ::HashWithIndifferentAccess . new ( request_id : "xyz" ) ) do
63+ Rails . logger . info ( "Hello World" )
64+ end
65+
66+ expect ( capture . last ) . to have_keys (
67+ message : be == "Hello World" ,
68+ request_id : be == "xyz"
69+ )
70+ expect ( capture . last ) . not . to have_keys ( "request_id" )
71+ end
72+
2473 it "should support silence" do
2574 expect ( Rails . logger ) . to be ( :respond_to? , :silence )
2675
0 commit comments