From 0e764a55991179dd371df8c0c5b5d5bd7fd2b793 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 17 Feb 2005 19:14:15 +0000 Subject: Addded validation for validate all the associated objects before declaring failure with validates_associated #618 [Tim Bates]. Added that validates_* now accept blocks to perform validations #618 [Tim Bates] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@650 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/validations.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record/validations.rb') diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 1e5d4287b0..a7811e50ac 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -51,7 +51,7 @@ module ActiveRecord alias_method :update_attribute_without_validation_skipping, :update_attribute alias_method :update_attribute, :update_attribute_with_validation_skipping - VALIDATIONS.each { |vd| base.class_eval("def self.#{vd}(*methods) write_inheritable_array(\"#{vd}\", methods - (read_inheritable_attribute(\"#{vd}\") || [])) end") } + VALIDATIONS.each { |vd| base.class_eval("def self.#{vd}(*methods, &block) write_inheritable_array(\"#{vd}\", methods + [block].compact - (read_inheritable_attribute(\"#{vd}\") || [])) end") } end base.extend(ClassMethods) @@ -300,7 +300,7 @@ module ActiveRecord for attr_name in attr_names class_eval(%(#{validation_method(configuration[:on])} %{ errors.add("#{attr_name}", "#{configuration[:message]}") unless - (#{attr_name}.is_a?(Array) ? #{attr_name} : [#{attr_name}]).inject(true){ |memo, record| memo and (record.nil? or record.valid?) } + (#{attr_name}.is_a?(Array) ? #{attr_name} : [#{attr_name}]).inject(true){ |memo, record| (record.nil? or record.valid?) and memo } })) end end @@ -378,7 +378,7 @@ module ActiveRecord eval(validation, binding) elsif validation_block?(validation) validation.call(self) - elsif filter_class?(validation, validation_method) + elsif validation_class?(validation, validation_method) validation.send(validation_method, self) else raise( -- cgit v1.2.3