2009-03-20 06:32:24 -04:00
|
|
|
module ActiveModel
|
|
|
|
module ValidationsRepairHelper
|
2009-05-29 18:23:38 -04:00
|
|
|
extend ActiveSupport::Concern
|
2009-03-20 06:32:24 -04:00
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
def repair_validations(*model_classes)
|
|
|
|
setup do
|
2009-09-08 11:10:14 -04:00
|
|
|
@_stored_callbacks = {}
|
|
|
|
model_classes.each do |k|
|
|
|
|
@_stored_callbacks[k] = k._validate_callbacks.dup
|
|
|
|
end
|
2009-03-20 06:32:24 -04:00
|
|
|
end
|
|
|
|
teardown do
|
2009-09-08 11:10:14 -04:00
|
|
|
model_classes.each do |k|
|
|
|
|
k._validate_callbacks = @_stored_callbacks[k]
|
|
|
|
k.__update_callbacks(:validate)
|
|
|
|
end
|
2009-03-20 06:32:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def repair_validations(*model_classes, &block)
|
2009-09-08 11:10:14 -04:00
|
|
|
@__stored_callbacks = {}
|
|
|
|
model_classes.each do |k|
|
|
|
|
@__stored_callbacks[k] = k._validate_callbacks.dup
|
|
|
|
end
|
2009-03-20 06:32:24 -04:00
|
|
|
return block.call
|
|
|
|
ensure
|
2009-09-08 11:10:14 -04:00
|
|
|
model_classes.each do |k|
|
|
|
|
k._validate_callbacks = @__stored_callbacks[k]
|
|
|
|
k.__update_callbacks(:validate)
|
|
|
|
end
|
2009-03-20 06:32:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|