From a3d66deb7a42d083d8d05801f38e40154f8450f7 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Wed, 16 May 2018 21:01:10 +0200 Subject: [PATCH] Preserve the frozen state when cloning Flows objects --- lib/rackstash/flows.rb | 1 + spec/rackstash/flows_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) 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