aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-12-23 13:30:58 +0100
committerJosé Valim <jose.valim@gmail.com>2009-12-23 13:30:58 +0100
commit74098e4cb6de01745db8f1d8d567645553ade7c5 (patch)
tree61998222e5d362991d50fdb68153414848410ae2 /activerecord
parente31077c9aaec05bdf5ea0386eb42fcc039d86a0a (diff)
downloadrails-74098e4cb6de01745db8f1d8d567645553ade7c5.tar.gz
rails-74098e4cb6de01745db8f1d8d567645553ade7c5.tar.bz2
rails-74098e4cb6de01745db8f1d8d567645553ade7c5.zip
No need to use ValidationsRepairHelper hack on ActiveModel anymore, Model.reset_callbacks(:validate) is enough. However, tests in ActiveRecord are still coupled, so moved ValidationsRepairHelper back there.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/validations/associated.rb2
-rw-r--r--activerecord/test/cases/helper.rb3
-rw-r--r--activerecord/test/cases/validations_repair_helper.rb35
3 files changed, 38 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb
index 6e6f4df415..66b78682ad 100644
--- a/activerecord/lib/active_record/validations/associated.rb
+++ b/activerecord/lib/active_record/validations/associated.rb
@@ -2,7 +2,7 @@ module ActiveRecord
module Validations
class AssociatedValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
- return if (value.is_a?(Array) ? value : [value]).compact.all?{ |r| r.valid? }
+ 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)
end
end
diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb
index 307320b964..243c05e665 100644
--- a/activerecord/test/cases/helper.rb
+++ b/activerecord/test/cases/helper.rb
@@ -62,9 +62,10 @@ unless ENV['FIXTURE_DEBUG']
end
end
+require "cases/validations_repair_helper"
class ActiveSupport::TestCase
include ActiveRecord::TestFixtures
- include ActiveModel::ValidationsRepairHelper
+ include ActiveRecord::ValidationsRepairHelper
self.fixture_path = FIXTURES_ROOT
self.use_instantiated_fixtures = false
diff --git a/activerecord/test/cases/validations_repair_helper.rb b/activerecord/test/cases/validations_repair_helper.rb
new file mode 100644
index 0000000000..e04738d209
--- /dev/null
+++ b/activerecord/test/cases/validations_repair_helper.rb
@@ -0,0 +1,35 @@
+module ActiveRecord
+ module ValidationsRepairHelper
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+ def repair_validations(*model_classes)
+ setup do
+ @_stored_callbacks = {}
+ model_classes.each do |k|
+ @_stored_callbacks[k] = k._validate_callbacks.dup
+ end
+ end
+ teardown do
+ model_classes.each do |k|
+ k._validate_callbacks = @_stored_callbacks[k]
+ k.__update_callbacks(:validate)
+ end
+ end
+ end
+ end
+
+ def repair_validations(*model_classes, &block)
+ @__stored_callbacks = {}
+ model_classes.each do |k|
+ @__stored_callbacks[k] = k._validate_callbacks.dup
+ end
+ return block.call
+ ensure
+ model_classes.each do |k|
+ k._validate_callbacks = @__stored_callbacks[k]
+ k.__update_callbacks(:validate)
+ end
+ end
+ end
+end