Skip to content

Commit

Permalink
Merge pull request #2691 from marsz/master
Browse files Browse the repository at this point in the history
fix: call #dup would raise MissingAttributeError while putting :mount_on in options
  • Loading branch information
mshibuya authored Aug 27, 2023
2 parents f31546a + b1f79da commit 9216dfc
Show file tree
Hide file tree
Showing 2 changed files with 12 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 @@ -46,7 +46,7 @@ def initialize_dup(other)
@_mounters[:"#{column}"] = nil
super
# The attribute needs to be cleared to prevent it from picked up as identifier
write_attribute(:"#{column}", nil)
write_attribute(_mounter(:#{column}).serialization_column, nil)
_mounter(:"#{column}").cache(old_uploaders)
end
Expand Down
11 changes: 11 additions & 0 deletions spec/orm/activerecord_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,17 @@ def initialize_dup(*)
expect(@event.dup.image.model).not_to eq @event
end
end

context ':mount_on in options' do
before { Event.mount_uploader(:image_v2, @uploader, mount_on: :image) }
it do
@event.image_v2 = stub_file('test.jpeg')
@event.save
new_event = @event.dup
expect(new_event).not_to be @event
expect(new_event.image_v2.model).to be new_event
end
end
end

describe 'when set as a nested attribute' do
Expand Down

0 comments on commit 9216dfc

Please sign in to comment.