aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-01-15 13:02:57 -0800
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-01-15 13:02:57 -0800
commit203f78732125a29bd04d088a09b8a515b6ba9951 (patch)
tree62f6b462bcf81fe0f962d580868973c61b55389b
parentf1d8f2af72e21d41efd02488f1c2dcf829e17783 (diff)
parent63333e600fd8cc22002547d08e6de6f577fd40d2 (diff)
downloadrails-203f78732125a29bd04d088a09b8a515b6ba9951.tar.gz
rails-203f78732125a29bd04d088a09b8a515b6ba9951.tar.bz2
rails-203f78732125a29bd04d088a09b8a515b6ba9951.zip
Merge pull request #8940 from adomokos/adding_tests_for_changed_attributes
Cleaning up ActiveModel::Dirty tests
-rw-r--r--activemodel/test/cases/dirty_test.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb
index 0b9f9537e2..ba45089cca 100644
--- a/activemodel/test/cases/dirty_test.rb
+++ b/activemodel/test/cases/dirty_test.rb
@@ -46,7 +46,7 @@ class DirtyTest < ActiveModel::TestCase
assert @model.name_changed?
end
- test "list of changed attributes" do
+ test "list of changed attribute keys" do
assert_equal [], @model.changed
@model.name = "Paul"
assert_equal ['name'], @model.changed
@@ -106,6 +106,17 @@ class DirtyTest < ActiveModel::TestCase
assert_equal [nil, "Jericho Cane"], @model.previous_changes['name']
end
+ test "previous value is preserved when changed after save" do
+ assert_equal({}, @model.changed_attributes)
+ @model.name = "Paul"
+ assert_equal({ "name" => nil }, @model.changed_attributes)
+
+ @model.save
+
+ @model.name = "John"
+ assert_equal({ "name" => "Paul" }, @model.changed_attributes)
+ end
+
test "changing the same attribute multiple times retains the correct original value" do
@model.name = "Otto"
@model.save