diff options
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activemodel/lib/active_model/dirty.rb | 5 | ||||
-rw-r--r-- | activemodel/test/cases/dirty_test.rb | 3 | ||||
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 5 |
4 files changed, 11 insertions, 6 deletions
diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index aacef97858..b955e98835 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 4.0.0 (unreleased) ## +* `[attribute]_changed?` now returns `false` after a call to `reset_[attribute]!` + + *Renato Mascarenhas* + * Observers was extracted from Active Model as `rails-observers` gem. *Rafael Mendonça França* diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index d47c3ae1bb..ecb7a9e9b1 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -174,7 +174,10 @@ module ActiveModel # Handle <tt>reset_*!</tt> for +method_missing+. def reset_attribute!(attr) - __send__("#{attr}=", changed_attributes[attr]) if attribute_changed?(attr) + if attribute_changed?(attr) + __send__("#{attr}=", changed_attributes[attr]) + changed_attributes.delete(attr) + end end end end diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb index eaaf910bac..0b9f9537e2 100644 --- a/activemodel/test/cases/dirty_test.rb +++ b/activemodel/test/cases/dirty_test.rb @@ -78,7 +78,7 @@ class DirtyTest < ActiveModel::TestCase @model.name = "Bob" @model.reset_name! assert_nil @model.name - #assert !@model.name_changed #Doesn't work yet + assert !@model.name_changed? end test "setting color to same value should not result in change being recorded" do @@ -114,5 +114,4 @@ class DirtyTest < ActiveModel::TestCase assert_equal ["Otto", "Mr. Manfredgensonton"], @model.name_change assert_equal @model.name_was, "Otto" end - end diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 293ce07f4e..1ffce1ae47 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -116,7 +116,7 @@ class ErrorsTest < ActiveModel::TestCase test "added? should default message to :invalid" do person = Person.new - person.errors.add(:name, :invalid) + person.errors.add(:name) assert person.errors.added?(:name) end @@ -161,7 +161,7 @@ class ErrorsTest < ActiveModel::TestCase person = Person.new person.errors.add(:name, "can not be blank") person.errors.add(:name, "can not be nil") - assert_equal ["name can not be blank", "name can not be nil"], person.errors.to_a + assert_equal ["name can not be blank", "name can not be nil"], person.errors.full_messages end test 'full_message should return the given message if attribute equals :base' do @@ -240,4 +240,3 @@ class ErrorsTest < ActiveModel::TestCase person.errors.add_on_blank :name, :message => 'custom' end end - |