From 63333e600fd8cc22002547d08e6de6f577fd40d2 Mon Sep 17 00:00:00 2001 From: Attila Domokos Date: Mon, 14 Jan 2013 15:03:42 -0500 Subject: Cleaning up ActiveModel::Dirty tests * Clarifying what the #changed method returns * Adding tests to describe what the #changed_attributes returns * Updating test name based on pull request comment * Moving the test lower in the file per pull request comment --- activemodel/test/cases/dirty_test.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'activemodel/test') 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 -- cgit v1.2.3