Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #112 from die-antwort/fix-remove-file-in-embedded-…

…document

Fix removing uploaded files in embedded documents.
  • Loading branch information...
commit 83d9961663d001dfa643e7bd353c0e59af997fcf 2 parents bb18692 + 6b2b516
@rmm5t rmm5t 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.