diff --git a/lib/rackstash/filter_chain.rb b/lib/rackstash/filter_chain.rb index ff6d7e1..5957d01 100644 --- a/lib/rackstash/filter_chain.rb +++ b/lib/rackstash/filter_chain.rb @@ -273,6 +273,15 @@ module Rackstash private + def initialize_copy(orig) + super + + mon_initialize + synchronize do + @filters = orig.to_a + end + end + def index_at(index) case index when Integer, ->(o) { o.respond_to?(:to_int) } diff --git a/spec/rackstash/filter_chain_spec.rb b/spec/rackstash/filter_chain_spec.rb index 8adf6c6..b12cfa7 100644 --- a/spec/rackstash/filter_chain_spec.rb +++ b/spec/rackstash/filter_chain_spec.rb @@ -225,6 +225,16 @@ describe Rackstash::FilterChain do end end + describe '#dup' do + it 'duplicates the filters array' do + filter_chain << a_filter + dupped = filter_chain.dup + + expect(filter_chain.length).to eql dupped.length + expect { filter_chain << a_filter }.not_to change { dupped.length } + end + end + describe '#each' do it 'yields each filter' do filter_chain << -> {}