File tree 3 files changed +47
-4
lines changed
spec/integration/fluent_logger_rails
3 files changed +47
-4
lines changed Original file line number Diff line number Diff line change 4
4
5
5
Bug Fixes:
6
6
7
- * None
7
+ * Formatter is now more defensive about incoming nil and array-of-nil values, after changes with Rails 7.x Rack::Logger identified the gap
8
8
9
9
Enhancements:
10
10
Original file line number Diff line number Diff line change @@ -43,10 +43,13 @@ def format_severity(severity)
43
43
end
44
44
45
45
def tagged ( *tags )
46
- add_tags ( *tags )
47
- yield self
46
+ tags = tags . flatten . compact if tags . is_a? ( Array )
47
+
48
+ add_tags ( *tags ) if tags
49
+
50
+ yield ( self )
48
51
ensure
49
- remove_tags ( *tags )
52
+ remove_tags ( *tags ) if tags
50
53
end
51
54
52
55
def add_tags ( *tags )
Original file line number Diff line number Diff line change 33
33
end
34
34
end
35
35
36
+ describe '#tagged' do
37
+ let ( :tags ) { nil }
38
+
39
+ context 'nil tag' do
40
+ it 'does not attempt to process the tags' do
41
+ expect ( formatter ) . not_to ( receive ( :remove_tags ) . with ( anything ) )
42
+
43
+ formatter . tagged ( tags ) { expect ( formatter . current_tags ) . to ( eq ( { tags : [ ] } ) ) }
44
+ end
45
+ end
46
+
47
+ context 'with a nested array of nil tags' do
48
+ let ( :tags ) { [ nil ] }
49
+
50
+ it 'does not attempt to process the tags' do
51
+ expect ( formatter ) . not_to ( receive ( :remove_tags ) . with ( anything ) )
52
+
53
+ formatter . tagged ( [ tags ] ) { expect ( formatter . current_tags ) . to ( eq ( { tags : [ ] } ) ) }
54
+ end
55
+ end
56
+
57
+ context 'with a string tag' do
58
+ let ( :tags ) { 'tag' }
59
+
60
+ it 'adds the tag' do
61
+ formatter . tagged ( tags ) { expect ( formatter . current_tags ) . to ( eq ( { tags : [ tags ] } ) ) }
62
+ end
63
+ end
64
+
65
+ context 'with a hash' do
66
+ let ( :tags ) { { port : 80 , host : '127.0.0.1' } }
67
+
68
+ it 'adds the tags' do
69
+ formatter . tagged ( **tags ) do
70
+ expect ( formatter . current_tags ) . to ( eq ( tags ) )
71
+ end
72
+ end
73
+ end
74
+ end
75
+
36
76
describe '#add_tags' do
37
77
context 'for a hash' do
38
78
before { formatter . add_tags ( host : '127.0.0.1' , port : '80' ) }
You can’t perform that action at this time.
0 commit comments