diff options
author | shock_one <shockone89@gmail.com> | 2013-03-24 09:34:27 +0200 |
---|---|---|
committer | shock_one <shockone89@gmail.com> | 2013-03-24 09:38:28 +0200 |
commit | ec1b715b0e6f0a345b94a44b2a03b6044091a706 (patch) | |
tree | 0ef0f800d850288341a8d89e9f7efe5b3a58b5cf /activemodel/test/cases/errors_test.rb | |
parent | 1f1adb835a679551b23de8c18514b747ef146137 (diff) | |
download | rails-ec1b715b0e6f0a345b94a44b2a03b6044091a706.tar.gz rails-ec1b715b0e6f0a345b94a44b2a03b6044091a706.tar.bz2 rails-ec1b715b0e6f0a345b94a44b2a03b6044091a706.zip |
Add a method full_messages_for to the Errors class
Diffstat (limited to 'activemodel/test/cases/errors_test.rb')
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 51dcfc37d8..5a9abe0204 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -216,6 +216,26 @@ class ErrorsTest < ActiveModel::TestCase person.errors.add(:name, "can not be nil") assert_equal ["name can not be blank", "name can not be nil"], person.errors.full_messages end + + test 'full_messages_for should contain all the messages for a given attribute' do + person = Person.new + person.errors.add(:name, "can not be blank") + person.errors.add(:name, "can not be nil") + assert_equal ["name can not be blank", "name can not be nil"], person.errors.full_messages_for(:name) + end + + test 'full_messages_for should not contain messages for another attributes' do + person = Person.new + person.errors.add(:name, "can not be blank") + person.errors.add(:email, "can not be blank") + assert_equal ["name can not be blank"], person.errors.full_messages_for(:name) + end + + test "full_messages_for should return an empty array in case if errors hash doesn't contain a given attribute" do + person = Person.new + person.errors.add(:name, "can not be blank") + assert_equal [], person.errors.full_messages_for(:email) + end test 'full_message should return the given message if attribute equals :base' do person = Person.new |