aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJeroen van Dijk <jeroen@jeevidee.nl>2010-05-19 15:25:46 +0100
committerJosé Valim <jose.valim@gmail.com>2010-06-21 11:55:21 +0200
commit26392c4ac57e27c63984d47c6326c13f502d5786 (patch)
treed3ee41f6eb5f8a394d059097629d84365936a995 /activerecord/lib
parentead72b319f781ae3767a8695e3e29e9249388f7f (diff)
downloadrails-26392c4ac57e27c63984d47c6326c13f502d5786.tar.gz
rails-26392c4ac57e27c63984d47c6326c13f502d5786.tar.bz2
rails-26392c4ac57e27c63984d47c6326c13f502d5786.zip
Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an options hash and make various Validators pass their (filtered) options.
This makes it possible to pass additional options through Validators to message generation. E.g. plugin authors want to add validates_presence_of :foo, :format => "some format". Also, cleanup the :default vs :message options confusion in ActiveModel validation message generation. Also, deprecate ActiveModel::Errors#add_on_blank(attributes, custom_message) in favor of ActiveModel::Errors#add_on_blank(attributes, options). Also, refactoring of ActiveModel and ActiveRecord Validation tests. Test are a lot more DRY now. Better test coverage as well now. The first four points were reapplied from an older patch of Sven Fuchs which didn't apply cleanly anymore and was not complete yet. Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/validations/associated.rb2
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb2
2 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb
index e41635134c..0b0f5682aa 100644
--- a/activerecord/lib/active_record/validations/associated.rb
+++ b/activerecord/lib/active_record/validations/associated.rb
@@ -3,7 +3,7 @@ module ActiveRecord
class AssociatedValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if (value.is_a?(Array) ? value : [value]).collect{ |r| r.nil? || r.valid? }.all?
- record.errors.add(attribute, :invalid, :default => options[:message], :value => value)
+ record.errors.add(attribute, :invalid, options.merge(:value => value))
end
end
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb
index 6283bdd0d6..1c9ecc7b1b 100644
--- a/activerecord/lib/active_record/validations/uniqueness.rb
+++ b/activerecord/lib/active_record/validations/uniqueness.rb
@@ -32,7 +32,7 @@ module ActiveRecord
end
if relation.exists?
- record.errors.add(attribute, :taken, :default => options[:message], :value => value)
+ record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
end
end