diff options
author | Josh Kalderimis <josh.kalderimis@gmail.com> | 2010-06-23 14:41:28 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-23 14:45:55 +0200 |
commit | e8c064bbe0fb5e07c7ceaa45d0cafa3c4ef01ab0 (patch) | |
tree | e1a4ab2fc6d37259721e69878c9f0123c1cd2b87 /activemodel/test | |
parent | 7008911222826eef07a338bf4cab27b83fe90ce1 (diff) | |
download | rails-e8c064bbe0fb5e07c7ceaa45d0cafa3c4ef01ab0.tar.gz rails-e8c064bbe0fb5e07c7ceaa45d0cafa3c4ef01ab0.tar.bz2 rails-e8c064bbe0fb5e07c7ceaa45d0cafa3c4ef01ab0.zip |
Regression with how base errors messages are added to a model. Works correctly for both string error messages and symbol translated messages.
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/validations_test.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index af195af080..228c1c074f 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -83,10 +83,9 @@ class ValidationsTest < ActiveModel::TestCase r = Reply.new r.content = "Mismatch" r.valid? - r.errors[:base] << "Reply is not dignifying" + r.errors.add(:base, "Reply is not dignifying") - errors = [] - r.errors.to_a.each { |error| errors << error } + errors = r.errors.to_a.inject([]) { |result, error| result + [error] } assert_equal ["Reply is not dignifying"], r.errors[:base] @@ -95,6 +94,22 @@ class ValidationsTest < ActiveModel::TestCase assert_equal 2, r.errors.count end + def test_errors_on_base_with_symbol_message + r = Reply.new + r.content = "Mismatch" + r.valid? + r.errors.add(:base, :invalid) + + errors = r.errors.to_a.inject([]) { |result, error| result + [error] } + + assert_equal ["is invalid"], r.errors[:base] + + assert errors.include?("Title is Empty") + assert errors.include?("is invalid") + + assert_equal 2, r.errors.count + end + def test_errors_empty_after_errors_on_check t = Topic.new assert t.errors[:id].empty? |