Skip to content

Commit

Permalink
Flush mounters on dup of active record model
Browse files Browse the repository at this point in the history
  • Loading branch information
danielevans committed Jan 15, 2015
1 parent 56873b0 commit b416406
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 @@ -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

0 comments on commit b416406

Please # to comment.