Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: call #dup would raise MissingAttributeError while putting :mount_on in options #2691

Merged
merged 1 commit into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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