Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix removing uploaded files in embedded documents.

Sending `remove_file = "1"` to an embedded document does not work: Mongoid won’t consider the document dirty and so `save` won’t do anything. (Note that this bug only occurs if there are no other changes to the document.)

I'm not 100% sure how this relates to #95 – calling `uploader_column_will_change!` seems to suffice in this case.
  • Loading branch information...
commit 6b2b5168fbfe9a30215848f968da1018e7f2f447 1 parent bb18692
@noniq noniq authored
Showing with 12 additions and 0 deletions.
  1. +6 −0 lib/carrierwave/mongoid.rb
  2. +6 −0 spec/mongoid_spec.rb
View
6 lib/carrierwave/mongoid.rb
@@ -43,6 +43,12 @@ def #{column}=(new_file)
super
end
+ def remove_#{column}=(arg)
+ column = _mounter(:#{column}).serialization_column
+ send(:"\#{column}_will_change!")
+ super
+ end
+
def remove_#{column}!
super unless respond_to?(:paranoid?) && paranoid? && flagged_for_destroy?
end
View
6 spec/mongoid_spec.rb
@@ -599,6 +599,12 @@ def filename
@doc.mongo_locations.first[:image].should == 'test.jpeg'
end
+ it "removes a file" do
+ @doc.update_attributes mongo_locations_attributes: { '0' => { _id: @embedded_doc._id, remove_image: "1" } }
+ @doc.reload
+ @doc.mongo_locations.first[:image].should_not be_present
+ end
+
describe 'with double embedded documents' do
before do
Please sign in to comment.
Something went wrong with that request. Please try again.