aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/validations
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2019-04-24 16:16:00 -0400
committerGitHub <noreply@github.com>2019-04-24 16:16:00 -0400
commitd4d145a6795ee7f461ef86a07e73a1f13fdb8574 (patch)
treeed4780a32c4e78d9890db43e02499e1b2e25d907 /activemodel/test/cases/validations
parent9834be65655e8552d25633b7376ab0654a23875d (diff)
parent5e24c333505c3bab3c85d834ac985281f141709f (diff)
downloadrails-d4d145a6795ee7f461ef86a07e73a1f13fdb8574.tar.gz
rails-d4d145a6795ee7f461ef86a07e73a1f13fdb8574.tar.bz2
rails-d4d145a6795ee7f461ef86a07e73a1f13fdb8574.zip
Merge pull request #32313 from lulalala/model_error_as_object
Model error as object
Diffstat (limited to 'activemodel/test/cases/validations')
-rw-r--r--activemodel/test/cases/validations/i18n_validation_test.rb19
-rw-r--r--activemodel/test/cases/validations/validations_context_test.rb4
-rw-r--r--activemodel/test/cases/validations/with_validation_test.rb8
3 files changed, 23 insertions, 8 deletions
diff --git a/activemodel/test/cases/validations/i18n_validation_test.rb b/activemodel/test/cases/validations/i18n_validation_test.rb
index 35bb918f26..b7ee50832c 100644
--- a/activemodel/test/cases/validations/i18n_validation_test.rb
+++ b/activemodel/test/cases/validations/i18n_validation_test.rb
@@ -169,8 +169,8 @@ class I18nValidationTest < ActiveModel::TestCase
# [ case, validation_options, generate_message_options]
[ "given no options", {}, {}],
[ "given custom message", { message: "custom" }, { message: "custom" }],
- [ "given if condition", { if: lambda { true } }, {}],
- [ "given unless condition", { unless: lambda { false } }, {}],
+ [ "given if condition", { if: lambda { true } }, {}],
+ [ "given unless condition", { unless: lambda { false } }, {}],
[ "given option that is not reserved", { format: "jpg" }, { format: "jpg" }]
]
@@ -181,6 +181,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title_confirmation, :confirmation, generate_message_options.merge(attribute: "Title")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -191,6 +192,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :accepted, generate_message_options]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -201,6 +203,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :blank, generate_message_options]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -211,6 +214,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :too_short, generate_message_options.merge(count: 3)]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -222,6 +226,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :too_long, generate_message_options.merge(count: 5)]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -232,6 +237,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :wrong_length, generate_message_options.merge(count: 5)]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -243,6 +249,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :invalid, generate_message_options.merge(value: "72x")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -254,6 +261,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :inclusion, generate_message_options.merge(value: "z")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -265,6 +273,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :inclusion, generate_message_options.merge(value: "z")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -276,6 +285,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :exclusion, generate_message_options.merge(value: "a")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -287,6 +297,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :exclusion, generate_message_options.merge(value: "a")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -298,6 +309,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :not_a_number, generate_message_options.merge(value: "a")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -309,6 +321,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :not_an_integer, generate_message_options.merge(value: "0.0")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -320,6 +333,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :odd, generate_message_options.merge(value: 0)]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
@@ -331,6 +345,7 @@ class I18nValidationTest < ActiveModel::TestCase
call = [:title, :less_than, generate_message_options.merge(value: 1, count: 0)]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
+ @person.errors.messages
end
end
end
diff --git a/activemodel/test/cases/validations/validations_context_test.rb b/activemodel/test/cases/validations/validations_context_test.rb
index 024eb1882f..3d2dea9828 100644
--- a/activemodel/test/cases/validations/validations_context_test.rb
+++ b/activemodel/test/cases/validations/validations_context_test.rb
@@ -14,13 +14,13 @@ class ValidationsContextTest < ActiveModel::TestCase
class ValidatorThatAddsErrors < ActiveModel::Validator
def validate(record)
- record.errors[:base] << ERROR_MESSAGE
+ record.errors.add(:base, ERROR_MESSAGE)
end
end
class AnotherValidatorThatAddsErrors < ActiveModel::Validator
def validate(record)
- record.errors[:base] << ANOTHER_ERROR_MESSAGE
+ record.errors.add(:base, ANOTHER_ERROR_MESSAGE)
end
end
diff --git a/activemodel/test/cases/validations/with_validation_test.rb b/activemodel/test/cases/validations/with_validation_test.rb
index 8239792c79..e6ae6603f2 100644
--- a/activemodel/test/cases/validations/with_validation_test.rb
+++ b/activemodel/test/cases/validations/with_validation_test.rb
@@ -14,13 +14,13 @@ class ValidatesWithTest < ActiveModel::TestCase
class ValidatorThatAddsErrors < ActiveModel::Validator
def validate(record)
- record.errors[:base] << ERROR_MESSAGE
+ record.errors.add(:base, message: ERROR_MESSAGE)
end
end
class OtherValidatorThatAddsErrors < ActiveModel::Validator
def validate(record)
- record.errors[:base] << OTHER_ERROR_MESSAGE
+ record.errors.add(:base, message: OTHER_ERROR_MESSAGE)
end
end
@@ -32,14 +32,14 @@ class ValidatesWithTest < ActiveModel::TestCase
class ValidatorThatValidatesOptions < ActiveModel::Validator
def validate(record)
if options[:field] == :first_name
- record.errors[:base] << ERROR_MESSAGE
+ record.errors.add(:base, message: ERROR_MESSAGE)
end
end
end
class ValidatorPerEachAttribute < ActiveModel::EachValidator
def validate_each(record, attribute, value)
- record.errors[attribute] << "Value is #{value}"
+ record.errors.add(attribute, message: "Value is #{value}")
end
end