From b41640610175932cd885f027840a275464b8ceaf Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Thu, 15 Jan 2015 14:00:09 -0700 Subject: [PATCH] Flush mounters on dup of active record model --- lib/carrierwave/orm/activerecord.rb | 6 ++++++ spec/orm/activerecord_spec.rb | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/carrierwave/orm/activerecord.rb b/lib/carrierwave/orm/activerecord.rb index c930d7768..b1bccfaf0 100644 --- a/lib/carrierwave/orm/activerecord.rb +++ b/lib/carrierwave/orm/activerecord.rb @@ -85,6 +85,12 @@ def reload @_mounters = nil super end + + # Reset cached mounter on record dup + def initialize_dup(other) + @_mounters = nil + super + end RUBY end diff --git a/spec/orm/activerecord_spec.rb b/spec/orm/activerecord_spec.rb index b5b54c60a..6c79ec8f2 100644 --- a/spec/orm/activerecord_spec.rb +++ b/spec/orm/activerecord_spec.rb @@ -1485,4 +1485,12 @@ def filename expect(File.exist?(public_path('uploads/old.jpeg'))).to be_true end end + + describe "#dup" do + it "appropriately removes the model reference from the new models uploader" do + @event.save + new_event = @event.dup + expect(new_event.image.model).not_to eq @event + end + end end