From 1c3bfb8353ea090cca27d3c82be476560457dffe Mon Sep 17 00:00:00 2001 From: Ben Marini Date: Sun, 13 Jun 2010 14:45:36 -0700 Subject: [PATCH] Add test for validation and callback definition order --- activemodel/test/cases/validation_callback_test.rb | 34 ++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-) create mode 100644 activemodel/test/cases/validation_callback_test.rb diff --git a/activemodel/test/cases/validation_callback_test.rb b/activemodel/test/cases/validation_callback_test.rb new file mode 100644 index 0000000..7f610c7 --- /dev/null +++ b/activemodel/test/cases/validation_callback_test.rb @@ -0,0 +1,34 @@ +require "cases/helper" + +class ValidationCallbackTest < ActiveModel::TestCase + + class Person + include ActiveModel::Validations + extend ActiveModel::Callbacks + define_model_callbacks :validate + + attr_accessor :name + + def default_name + @name = "John Smith" + end + end + + class PersonWithCallbackFirst < Person + before_validate :default_name + validate { validates_presence_of :name } + end + + class PersonWithCallbackLast < Person + validate { validates_presence_of :name } + before_validate :default_name + end + + test "should run callback before validation when callback defined before" do + assert PersonWithCallbackFirst.new.valid? + end + + test "should run callback before validation when callback defined after" do + assert PersonWithCallbackLast.new.valid? + end +end -- 1.7.0.6