diff --git a/lib/rackstash/flows.rb b/lib/rackstash/flows.rb index 3c37ec5..060f989 100644 --- a/lib/rackstash/flows.rb +++ b/lib/rackstash/flows.rb @@ -229,6 +229,7 @@ module Rackstash def initialize_copy(other) @flows = other.flows.dup + @flows.freeze if other.frozen? super end diff --git a/spec/rackstash/flows_spec.rb b/spec/rackstash/flows_spec.rb index a97f4e0..387e523 100644 --- a/spec/rackstash/flows_spec.rb +++ b/spec/rackstash/flows_spec.rb @@ -155,6 +155,25 @@ RSpec.describe Rackstash::Flows do end end + describe '#clone' do + it 'clones the flows' do + flows << a_flow + copied = flows.clone + + expect(copied).to be_instance_of described_class + expect(copied.length).to eql 1 + expect(copied).to_not equal flows + end + + it 'preserves the frozen? status' do + flows.freeze + expect(flows).to be_frozen + + expect(flows.clone).to be_frozen + expect { flows.clone << a_flow }.to raise_error(RuntimeError) + end + end + describe '#freeze' do it 'freezes the object' do expect(flows.freeze).to equal flows