From 051d859880dde2896cc5417844e566569466b28c Mon Sep 17 00:00:00 2001 From: Sen-Zhang Date: Mon, 11 Apr 2016 19:33:52 -0700 Subject: [PATCH] prevent 'attribute_changed?' from returning nil --- activemodel/lib/active_model/dirty.rb | 2 +- activerecord/test/cases/dirty_test.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index fad4de9df5..9aca5f2c90 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -180,7 +180,7 @@ module ActiveModel result &&= options[:to] == __send__(attr) if options.key?(:to) result &&= options[:from] == changed_attributes[attr] if options.key?(:from) end - result + !!result end # Handles *_was for +method_missing+. diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index cd1967c373..a3f8d26100 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -37,8 +37,8 @@ class DirtyTest < ActiveRecord::TestCase def test_attribute_changes # New record - no changes. pirate = Pirate.new - assert !pirate.catchphrase_changed? - assert_nil pirate.catchphrase_change + assert_equal false, pirate.catchphrase_changed? + assert_equal false, pirate.non_validated_parrot_id_changed? # Change catchphrase. pirate.catchphrase = 'arrr'