diff options
author | Yehuda Katz <wycats@Yehuda-Katz.local> | 2009-12-28 16:19:09 -0800 |
---|---|---|
committer | Yehuda Katz <wycats@Yehuda-Katz.local> | 2009-12-28 16:19:09 -0800 |
commit | 643862e3be1bbe004e2c1a00286b12c5bdc9849a (patch) | |
tree | e2c6749496100a45631a2faea6ff216808fe83f0 /activerecord/test/cases/validations_repair_helper.rb | |
parent | 9abbe9f0b311418b19e9c036e9b67c84a6bf2b7c (diff) | |
parent | 078ea0dfbdfa3267da13e88536dc73aa477a162c (diff) | |
download | rails-643862e3be1bbe004e2c1a00286b12c5bdc9849a.tar.gz rails-643862e3be1bbe004e2c1a00286b12c5bdc9849a.tar.bz2 rails-643862e3be1bbe004e2c1a00286b12c5bdc9849a.zip |
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'activerecord/test/cases/validations_repair_helper.rb')
-rw-r--r-- | activerecord/test/cases/validations_repair_helper.rb | 35 |
1 files changed, 35 insertions, 0 deletions
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 |