Restored the condition to execute write_uploader

resolve #2608
This commit is contained in:
wonda-tea-coffee 2022-06-18 15:26:07 +09:00
parent 774c63d508
commit 36dac97704
2 changed files with 28 additions and 4 deletions

View File

@ -174,8 +174,12 @@ module CarrierWave
return if frozen?
mounter = _mounter(:#{column})
mounter.clear! if mounter.remove?
write_uploader(mounter.serialization_column, mounter.identifiers.first)
if mounter.remove?
mounter.clear!
write_uploader(mounter.serialization_column, nil)
elsif mounter.identifiers.first
write_uploader(mounter.serialization_column, mounter.identifiers.first)
end
end
def #{column}_identifier
@ -349,8 +353,12 @@ module CarrierWave
return if frozen?
mounter = _mounter(:#{column})
mounter.clear! if mounter.remove?
write_uploader(mounter.serialization_column, mounter.identifiers.presence)
if mounter.remove?
mounter.clear!
write_uploader(mounter.serialization_column, nil)
elsif mounter.identifiers.any?
write_uploader(mounter.serialization_column, mounter.identifiers)
end
end
def #{column}_identifiers

View File

@ -429,6 +429,14 @@ describe CarrierWave::ActiveRecord do
expect(@event.image_changed?).to be_truthy
expect(@event.changed_for_autosave?).to be_truthy
end
it "should not update image when save with select" do
@event.image = stub_file('test.jpeg')
@event.save!
Event.select(:id).first.save!
@event.reload
expect(@event.image).to be_present
end
end
describe "image?" do
@ -1264,6 +1272,14 @@ describe CarrierWave::ActiveRecord do
expect(@event.images_changed?).to be_truthy
expect(@event.changed_for_autosave?).to be_truthy
end
it "should not update image when save with select" do
@event.images = [stub_file('test.jpeg')]
@event.save!
Event.select(:id).first.save!
@event.reload
expect(@event.images).to be_present
end
end
describe "remove_images!" do