Skip to content

Commit

Permalink
Fix #dup modifying the original object
Browse files Browse the repository at this point in the history
Fixes #2687
  • Loading branch information
mshibuya committed Aug 19, 2023
1 parent 26b6bbd commit 37f36f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/carrierwave/orm/activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def reload(*)
def initialize_dup(other)
old_uploaders = _mounter(:"#{column}").uploaders
@_mounters[:"#{column}"] = nil
super
# The attribute needs to be cleared to prevent it from picked up as identifier
write_attribute(:"#{column}", nil)
super
_mounter(:"#{column}").cache(old_uploaders)
end
Expand Down
6 changes: 6 additions & 0 deletions spec/orm/activerecord_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,12 @@ def reload(*)
expect(new_event.image.url).to eq '/uploads/test.jpeg'
end

it "does not modify the original object" do
@event.image = stub_file('test.jpeg')
@event.save
expect { @event.dup }.not_to change { @event[:image] }
end

context "with more than one mount" do
before do
@uploader1 = Class.new(CarrierWave::Uploader::Base)
Expand Down

0 comments on commit 37f36f7

Please sign in to comment.