aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorZamith <zamith.28@gmail.com>2015-05-04 13:36:26 +0100
committerZamith <zamith.28@gmail.com>2015-05-04 13:36:26 +0100
commit6f418a09d82351ae74409379f80012f717aa9cb0 (patch)
tree58f68e5f6129e30c2e305e3f4797fdbe59ae22aa /activemodel
parent21c74bd769f6c873453e9244b0de7ced40a532be (diff)
downloadrails-6f418a09d82351ae74409379f80012f717aa9cb0.tar.gz
rails-6f418a09d82351ae74409379f80012f717aa9cb0.tar.bz2
rails-6f418a09d82351ae74409379f80012f717aa9cb0.zip
Adds/Corrects use case for adding an error message
I believe this is a use case that was supposed to be supported, and it's a small fix.
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/errors.rb2
-rw-r--r--activemodel/test/cases/errors_test.rb6
2 files changed, 7 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index f843b279ce..287a2559d2 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -452,7 +452,6 @@ module ActiveModel
defaults = []
end
- defaults << options.delete(:message)
defaults << :"#{@base.class.i18n_scope}.errors.messages.#{type}" if @base.class.respond_to?(:i18n_scope)
defaults << :"errors.attributes.#{attribute}.#{type}"
defaults << :"errors.messages.#{type}"
@@ -461,6 +460,7 @@ module ActiveModel
defaults.flatten!
key = defaults.shift
+ defaults = options.delete(:message) if options[:message]
value = (attribute != :base ? @base.send(:read_attribute_for_validation, attribute) : nil)
options = {
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb
index f781a0017f..d10c20caad 100644
--- a/activemodel/test/cases/errors_test.rb
+++ b/activemodel/test/cases/errors_test.rb
@@ -149,6 +149,12 @@ class ErrorsTest < ActiveModel::TestCase
assert_equal ["cannot be blank"], person.errors[:name]
end
+ test "add an error message on a specific attribute with a defined type" do
+ person = Person.new
+ person.errors.add(:name, :blank, message: "cannot be blank")
+ assert_equal ["cannot be blank"], person.errors[:name]
+ end
+
test "add an error with a symbol" do
person = Person.new
person.errors.add(:name, :blank)