Skip to content

Commit

Permalink
Merge pull request #112 from die-antwort/fix-remove-file-in-embedded-…
Browse files Browse the repository at this point in the history
…document

Fix removing uploaded files in embedded documents.
  • Loading branch information
rmm5t committed Sep 3, 2013
2 parents bb18692 + 6b2b516 commit 83d9961
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/carrierwave/mongoid.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def #{column}=(new_file)
super super
end end
def remove_#{column}=(arg)
column = _mounter(:#{column}).serialization_column
send(:"\#{column}_will_change!")
super
end
def remove_#{column}! def remove_#{column}!
super unless respond_to?(:paranoid?) && paranoid? && flagged_for_destroy? super unless respond_to?(:paranoid?) && paranoid? && flagged_for_destroy?
end end
Expand Down
6 changes: 6 additions & 0 deletions spec/mongoid_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -599,6 +599,12 @@ def filename
@doc.mongo_locations.first[:image].should == 'test.jpeg' @doc.mongo_locations.first[:image].should == 'test.jpeg'
end 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 describe 'with double embedded documents' do


before do before do
Expand Down

0 comments on commit 83d9961

Please sign in to comment.