Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #130 from schnittchen/master

don't announce upcoming attribute change when remove_ virtual setter called with unchecked value
  • Loading branch information...
commit ee7d38e353df55ed5be51446233f54c93c0ad3e0 2 parents f19f0b5 + 6ad1b4e
Ryan McGeary rmm5t authored
Showing with 37 additions and 3 deletions.
  1. +4 −2 lib/carrierwave/mongoid.rb
  2. +33 −1 spec/mongoid_spec.rb
6 lib/carrierwave/mongoid.rb
View
@@ -44,8 +44,10 @@ def #{column}=(new_file)
end
def remove_#{column}=(arg)
- column = _mounter(:#{column}).serialization_column
- send(:"\#{column}_will_change!")
+ if ['1', true].include?(arg)
+ column = _mounter(:#{column}).serialization_column
+ send(:"\#{column}_will_change!")
+ end
super
end
34 spec/mongoid_spec.rb
View
@@ -238,6 +238,38 @@ def extension_white_list
end
+ describe '#remove_image=' do
+ before do
+ mongo_user_klass = reset_mongo_class
+ @doc = mongo_user_klass.new
+ end
+
+ it "treats true argument such that attribute is marked as changed" do
+ @doc.remove_image = true
+ @doc.should be_image_changed
+ end
+
+ it "treats '1' argument such that attribute is marked as changed" do
+ @doc.remove_image = '1'
+ @doc.should be_image_changed
+ end
+
+ it "treats false argument such that attribute is not marked as changed" do
+ @doc.remove_image = false
+ @doc.should_not be_image_changed
+ end
+
+ it "treats nil argument such that attribute is not marked as changed" do
+ @doc.remove_image = nil
+ @doc.should_not be_image_changed
+ end
+
+ it "treats '0' argument such that attribute is not marked as changed" do
+ @doc.remove_image = '0'
+ @doc.should_not be_image_changed
+ end
+ end
+
describe "#save" do
it "after it was initialized with params" do
@@ -790,7 +822,7 @@ def filename
end
end
- describe '#mount_uploader removing old files with with mount_on' do
+ describe '#mount_uploader removing old files with mount_on' do
before do
@class = reset_mongo_class
Please sign in to comment.
Something went wrong with that request. Please try again.