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