From da2b05bb6b713a702eb0420079394bf273f1203e Mon Sep 17 00:00:00 2001 From: Tejas Dinkar Date: Mon, 2 Dec 2013 10:20:43 +0530 Subject: Allows you to check if an attribute has changed to a particular value model.name_changed?(from: "Pete", to: "Ringo") --- activemodel/test/cases/dirty_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activemodel/test') diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb index a90d0b1299..54427a1513 100644 --- a/activemodel/test/cases/dirty_test.rb +++ b/activemodel/test/cases/dirty_test.rb @@ -67,6 +67,16 @@ class DirtyTest < ActiveModel::TestCase assert_equal [nil, "John"], @model.changes['name'] end + test "checking if an attribute has changed to a particular value" do + @model.name = "Ringo" + assert @model.name_changed?(from: nil, to: "Ringo") + assert_not @model.name_changed?(from: "Pete", to: "Ringo") + assert @model.name_changed?(to: "Ringo") + assert_not @model.name_changed?(to: "Pete") + assert @model.name_changed?(from: nil) + assert_not @model.name_changed?(from: "Pete") + end + test "changes accessible through both strings and symbols" do @model.name = "David" assert_not_nil @model.changes[:name] -- cgit v1.2.3