Skip to content

Commit

Permalink
Do not trigger *_will_change! when file is not to be removed. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Jun 19, 2019
1 parent 0f733d2 commit eab8267
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/carrierwave/orm/activerecord.rb
Expand Up @@ -77,8 +77,9 @@ def #{column}=(new_file)
def remove_#{column}=(value)
column = _mounter(:#{column}).serialization_column
__send__(:"\#{column}_will_change!")
super
result = super
__send__(:"\#{column}_will_change!") if _mounter(:#{column}).remove?
result
end
def remove_#{column}!
Expand Down
7 changes: 7 additions & 0 deletions spec/orm/activerecord_spec.rb
Expand Up @@ -1249,6 +1249,13 @@ def monkey
@event.remove_images = "1"
expect(@event.images_changed?).to be_truthy
end

it "should not mark the images as changed if falsey value is assigned" do
@event.remove_images = "0"
expect(@event.images_changed?).to be_falsey
@event.remove_images = "false"
expect(@event.images_changed?).to be_falsey
end
end

describe "#remote_images_urls=" do
Expand Down

0 comments on commit eab8267

Please sign in to comment.