diff --git a/lib/rackstash/fields/tags.rb b/lib/rackstash/fields/tags.rb index 0a57d81..8bafe84 100644 --- a/lib/rackstash/fields/tags.rb +++ b/lib/rackstash/fields/tags.rb @@ -41,7 +41,7 @@ module Rackstash end def merge!(tags, scope: nil) - @raw.merge normalize_tags(tags) + @raw.merge normalize_tags(tags, scope: scope) self end @@ -61,11 +61,11 @@ module Rackstash if value.is_a?(self.class) value.to_a elsif value.is_a?(Set) - value = value.map { |tag| normalize_tags(tag) } + value = value.map { |tag| normalize_tags(tag, scope: scope) } value.flatten! value elsif value.respond_to?(:to_ary) - value = value.to_ary.map { |tag| normalize_tags(tag) } + value = value.to_ary.map { |tag| normalize_tags(tag, scope: scope) } value.flatten! value else diff --git a/spec/rackstash/fields/tags_spec.rb b/spec/rackstash/fields/tags_spec.rb index 904475b..67c7900 100644 --- a/spec/rackstash/fields/tags_spec.rb +++ b/spec/rackstash/fields/tags_spec.rb @@ -11,7 +11,7 @@ describe Rackstash::Fields::Tags do let(:tags) { Rackstash::Fields::Tags.new } describe '#<<' do - it 'calls merge!' do + it 'adds a single tag' do tags << 'tag' expect(tags.tagged?('tag')).to be true end @@ -94,7 +94,10 @@ describe Rackstash::Fields::Tags do it 'resolves procs' do tags.merge! [-> { 123 }] - expect(tags.tagged?('123')).to be true + expect(tags.to_a).to eql ['123'] + + tags.merge! [-> { self }], scope: :foo + expect(tags.to_a).to eql ['123', 'foo'] end it 'flattens arguments' do