diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2013-12-30 22:05:56 -0800 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2013-12-30 22:05:56 -0800 |
commit | f3a8be3b8be496cd5de14e9c29de3748432d5da0 (patch) | |
tree | 4579d98d98223e87c958368f5cf16146144a136e /activemodel/test | |
parent | 969a0778cd2fd809a7b4f60c8477bb6d0ac9faf3 (diff) | |
parent | da2b05bb6b713a702eb0420079394bf273f1203e (diff) | |
download | rails-f3a8be3b8be496cd5de14e9c29de3748432d5da0.tar.gz rails-f3a8be3b8be496cd5de14e9c29de3748432d5da0.tar.bz2 rails-f3a8be3b8be496cd5de14e9c29de3748432d5da0.zip |
Merge pull request #13131 from gja/changed-accepts-values
Allows you to check if a field has changed to a particular value
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/dirty_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
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] |