aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test
diff options
context:
space:
mode:
authorKenichi Kamiya <kachick1@gmail.com>2016-02-15 01:41:59 +0900
committerKenichi Kamiya <kachick1@gmail.com>2016-11-22 04:10:41 +0900
commit9f566aba3278e6e64beb38a88c02a3528760c730 (patch)
tree3b579474d01c159fcd422e40c7f79b992d7bf301 /activemodel/test
parent2b4a9735d816d3a05c7fca207d97bebcb09c95a0 (diff)
downloadrails-9f566aba3278e6e64beb38a88c02a3528760c730.tar.gz
rails-9f566aba3278e6e64beb38a88c02a3528760c730.tar.bz2
rails-9f566aba3278e6e64beb38a88c02a3528760c730.zip
Allow indifferent access in ActiveModel::Errors
`#[]` has already applied indifferent access, but some methods does not. `#include?`, `#has_key?`, `#key?`, `#delete` and `#full_messages_for`.
Diffstat (limited to 'activemodel/test')
-rw-r--r--activemodel/test/cases/errors_test.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb
index 605ad64e4d..fc840bf192 100644
--- a/activemodel/test/cases/errors_test.rb
+++ b/activemodel/test/cases/errors_test.rb
@@ -30,7 +30,7 @@ class ErrorsTest < ActiveModel::TestCase
def test_delete
errors = ActiveModel::Errors.new(self)
errors[:foo] << "omg"
- errors.delete(:foo)
+ errors.delete("foo")
assert_empty errors[:foo]
end
@@ -38,6 +38,7 @@ class ErrorsTest < ActiveModel::TestCase
errors = ActiveModel::Errors.new(self)
errors[:foo] << "omg"
assert_includes errors, :foo, "errors should include :foo"
+ assert_includes errors, "foo", "errors should include 'foo' as :foo"
end
def test_dup
@@ -52,6 +53,7 @@ class ErrorsTest < ActiveModel::TestCase
errors = ActiveModel::Errors.new(self)
errors[:foo] << "omg"
assert_equal true, errors.has_key?(:foo), "errors should have key :foo"
+ assert_equal true, errors.has_key?("foo"), "errors should have key 'foo' as :foo"
end
def test_has_no_key
@@ -63,6 +65,7 @@ class ErrorsTest < ActiveModel::TestCase
errors = ActiveModel::Errors.new(self)
errors[:foo] << "omg"
assert_equal true, errors.key?(:foo), "errors should have key :foo"
+ assert_equal true, errors.key?("foo"), "errors should have key 'foo' as :foo"
end
def test_no_key
@@ -150,10 +153,11 @@ class ErrorsTest < ActiveModel::TestCase
assert_equal ["cannot be blank"], person.errors[:name]
end
- test "added? detects if a specific error was added to the object" do
+ test "added? detects indifferent if a specific error was added to the object" do
person = Person.new
person.errors.add(:name, "cannot be blank")
assert person.errors.added?(:name, "cannot be blank")
+ assert person.errors.added?("name", "cannot be blank")
end
test "added? handles symbol message" do
@@ -241,7 +245,7 @@ class ErrorsTest < ActiveModel::TestCase
assert_equal ["name cannot be blank", "name cannot be nil"], person.errors.full_messages
end
- test "full_messages_for contains all the error messages for the given attribute" do
+ test "full_messages_for contains all the error messages for the given attribute indifferent" do
person = Person.new
person.errors.add(:name, "cannot be blank")
person.errors.add(:name, "cannot be nil")
@@ -253,6 +257,7 @@ class ErrorsTest < ActiveModel::TestCase
person.errors.add(:name, "cannot be blank")
person.errors.add(:email, "cannot be blank")
assert_equal ["name cannot be blank"], person.errors.full_messages_for(:name)
+ assert_equal ["name cannot be blank"], person.errors.full_messages_for("name")
end
test "full_messages_for returns an empty list in case there are no errors for the given attribute" do