diff options
author | bogdanvlviv <bogdanvlviv@gmail.com> | 2017-03-28 12:05:14 +0300 |
---|---|---|
committer | bogdanvlviv <bogdanvlviv@gmail.com> | 2017-03-28 18:48:56 +0300 |
commit | 01269aede398f63e5ef68ebe0f0dafbc472c686e (patch) | |
tree | eeb2a2fc509cb384d012e7ef5147aa09329ecbcd /activemodel/test | |
parent | d28c48243521a978ba8d432092e11a4aafb2b154 (diff) | |
download | rails-01269aede398f63e5ef68ebe0f0dafbc472c686e.tar.gz rails-01269aede398f63e5ef68ebe0f0dafbc472c686e.tar.bz2 rails-01269aede398f63e5ef68ebe0f0dafbc472c686e.zip |
Fix ActiveModel::Errors #keys, #values
Before:
person.errors.keys # => []
person.errors.values # => []
person.errors[:name] # => []
person.errors.keys # => [:name]
person.errors.values # => [[]]
After:
person.errors.keys # => []
person.errors.values # => []
person.errors[:name] # => []
person.errors.keys # => []
person.errors.values # => []
Related to #23468
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 0872084cf5..43aee5a814 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -99,6 +99,14 @@ class ErrorsTest < ActiveModel::TestCase assert_equal ["omg", "zomg"], errors.values end + test "values returns an empty array after try to get a message only" do + errors = ActiveModel::Errors.new(self) + errors.messages[:foo] + errors.messages[:baz] + + assert_equal [], errors.values + end + test "keys returns the error keys" do errors = ActiveModel::Errors.new(self) errors.messages[:foo] << "omg" @@ -107,6 +115,14 @@ class ErrorsTest < ActiveModel::TestCase assert_equal [:foo, :baz], errors.keys end + test "keys returns an empty array after try to get a message only" do + errors = ActiveModel::Errors.new(self) + errors.messages[:foo] + errors.messages[:baz] + + assert_equal [], errors.keys + end + test "detecting whether there are errors with empty?, blank?, include?" do person = Person.new person.errors[:foo] |