diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2014-01-23 08:30:04 -0800 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2014-01-23 08:30:04 -0800 |
commit | a7680ab47ddaf3f963824a72a130e2b18fbd1195 (patch) | |
tree | 351c2a7b3422d92c07400c19dfe6bd470b9e3e47 /activemodel | |
parent | 6ef0569b0bf6e13d63f6c51790745b2007b92973 (diff) | |
parent | db95c7dcebcd240ba46cc5df4eb2b8f240f497bb (diff) | |
download | rails-a7680ab47ddaf3f963824a72a130e2b18fbd1195.tar.gz rails-a7680ab47ddaf3f963824a72a130e2b18fbd1195.tar.bz2 rails-a7680ab47ddaf3f963824a72a130e2b18fbd1195.zip |
Merge pull request #13795 from bobbus/errors-has-key
Fix ActiveModel::Errors#has_key? returning nil
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 2 | ||||
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 7 |
2 files changed, 7 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 010c4bb6f9..9c3bc913e1 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -94,7 +94,7 @@ module ActiveModel # person.errors.include?(:name) # => true # person.errors.include?(:age) # => false def include?(attribute) - (v = messages[attribute]) && v.any? + messages[attribute].present? end # aliases include? alias :has_key? :include? diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index bbd186d83d..def28578f8 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -51,7 +51,12 @@ class ErrorsTest < ActiveModel::TestCase def test_has_key? errors = ActiveModel::Errors.new(self) errors[:foo] = 'omg' - assert errors.has_key?(:foo), 'errors should have key :foo' + assert_equal true, errors.has_key?(:foo), 'errors should have key :foo' + end + + def test_has_no_key + errors = ActiveModel::Errors.new(self) + assert_equal false, errors.has_key?(:name), 'errors should not have key :name' end test "clear errors" do |