Skip to content

Commit

Permalink
Merge pull request #1544 from danielevans/bug/activerecord_dup
Browse files Browse the repository at this point in the history
Flush mounters on dup of active record model
  • Loading branch information
bensie committed Feb 26, 2015
2 parents bbef19c + b416406 commit 79b8e24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/carrierwave/orm/activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions spec/orm/activerecord_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1495,4 +1495,12 @@ def filename
expect { @event.with_lock {} }.to_not raise_error
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

0 comments on commit 79b8e24

Please # to comment.