diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-08 23:50:24 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-08 23:50:31 +0100 |
commit | 93898b389bafebc4d1b30a95330b4bb7d000c92d (patch) | |
tree | 67d411043d46a388f2dff75e51548d4c5c017410 /activerecord/lib/active_record/validations | |
parent | d4589e96ef5a2adaa81dac09869eefdadb24d6ee (diff) | |
download | rails-93898b389bafebc4d1b30a95330b4bb7d000c92d.tar.gz rails-93898b389bafebc4d1b30a95330b4bb7d000c92d.tar.bz2 rails-93898b389bafebc4d1b30a95330b4bb7d000c92d.zip |
Ensure new validates works with uniqueness validator.
Diffstat (limited to 'activerecord/lib/active_record/validations')
-rw-r--r-- | activerecord/lib/active_record/validations/associated.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/validations/uniqueness.rb | 9 |
2 files changed, 7 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb index 66b78682ad..e41635134c 100644 --- a/activerecord/lib/active_record/validations/associated.rb +++ b/activerecord/lib/active_record/validations/associated.rb @@ -40,8 +40,7 @@ module ActiveRecord # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The # method, proc or string should return or evaluate to a true or false value. def validates_associated(*attr_names) - options = attr_names.extract_options! - validates_with AssociatedValidator, options.merge(:attributes => attr_names) + validates_with AssociatedValidator, _merge_attributes(attr_names) end end end diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb index 7efd312357..4ff851dfa1 100644 --- a/activerecord/lib/active_record/validations/uniqueness.rb +++ b/activerecord/lib/active_record/validations/uniqueness.rb @@ -2,10 +2,14 @@ module ActiveRecord module Validations class UniquenessValidator < ActiveModel::EachValidator def initialize(options) - @klass = options.delete(:klass) super(options.reverse_merge(:case_sensitive => true)) end + # Unfortunately, we have to tie Uniqueness validators to a class. + def setup(klass) + @klass = klass + end + def validate_each(record, attribute, value) finder_class = find_finder_class_for(record) table = finder_class.active_relation @@ -170,8 +174,7 @@ module ActiveRecord # such a case. # def validates_uniqueness_of(*attr_names) - options = attr_names.extract_options! - validates_with UniquenessValidator, options.merge(:attributes => attr_names, :klass => self) + validates_with UniquenessValidator, _merge_attributes(attr_names) end end end |