Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #8940 from adomokos/adding_tests_for_changed_attri…

…butes

Cleaning up ActiveModel::Dirty tests
  • Loading branch information...
commit 203f78732125a29bd04d088a09b8a515b6ba9951 2 parents f1d8f2a + 63333e6
Carlos Antonio da Silva carlosantoniodasilva authored
Showing with 12 additions and 1 deletion.
  1. +12 −1 activemodel/test/cases/dirty_test.rb
13 activemodel/test/cases/dirty_test.rb
View
@@ -46,7 +46,7 @@ def save
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 @@ def save
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
Please sign in to comment.
Something went wrong with that request. Please try again.