Skip to content

Commit

Permalink
add failing test for carrierwaveuploader#2689
Browse files Browse the repository at this point in the history
duplication should not affect the duplicated objects path
  • Loading branch information
Yohta Kimura committed Aug 22, 2023
1 parent f31546a commit c6d0aa9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/orm/activerecord_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1991,6 +1991,28 @@ def reload(*)
end
end

context 'with store_dir using model attributes' do
before do
@uploader.class_eval do
def store_dir
"uploads/#{model.class.name.downcase}/#{mounted_as}/#{model.id}"
end
end
end

it "wont affect the duplicated object's saved path" do
@event.image = stub_file('test.jpeg')
expect(@event.save).to be_truthy
expect(@event.image.current_path).to eq public_path("uploads/event/image/#{@event.id}/test.jpeg")
new_event = @event.dup

expect(new_event).not_to be @event
expect(new_event.image.model).to be new_event
expect(@event.save).to be_truthy
expect(@event.image.current_path).to eq public_path("uploads/event/image/#{@event.id}/test.jpeg")
end
end

context 'when #initialize_dup is overridden in the model' do
before do
Event.class_eval do
Expand Down

0 comments on commit c6d0aa9

Please sign in to comment.