diff options
Diffstat (limited to 'activemodel/test/cases/validations/callbacks_test.rb')
-rw-r--r-- | activemodel/test/cases/validations/callbacks_test.rb | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/activemodel/test/cases/validations/callbacks_test.rb b/activemodel/test/cases/validations/callbacks_test.rb index 75eb18e795..99913be752 100644 --- a/activemodel/test/cases/validations/callbacks_test.rb +++ b/activemodel/test/cases/validations/callbacks_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require "cases/helper" class Dog include ActiveModel::Validations @@ -15,37 +15,37 @@ class DogWithMethodCallbacks < Dog before_validation :set_before_validation_marker after_validation :set_after_validation_marker - def set_before_validation_marker; self.history << 'before_validation_marker'; end - def set_after_validation_marker; self.history << 'after_validation_marker' ; end + def set_before_validation_marker; self.history << "before_validation_marker"; end + def set_after_validation_marker; self.history << "after_validation_marker" ; end end class DogValidatorsAreProc < Dog - before_validation { self.history << 'before_validation_marker' } - after_validation { self.history << 'after_validation_marker' } + before_validation { self.history << "before_validation_marker" } + after_validation { self.history << "after_validation_marker" } end class DogWithTwoValidators < Dog - before_validation { self.history << 'before_validation_marker1' } - before_validation { self.history << 'before_validation_marker2' } + before_validation { self.history << "before_validation_marker1" } + before_validation { self.history << "before_validation_marker2" } end class DogDeprecatedBeforeValidatorReturningFalse < Dog before_validation { false } - before_validation { self.history << 'before_validation_marker2' } + before_validation { self.history << "before_validation_marker2" } end class DogBeforeValidatorThrowingAbort < Dog before_validation { throw :abort } - before_validation { self.history << 'before_validation_marker2' } + before_validation { self.history << "before_validation_marker2" } end class DogAfterValidatorReturningFalse < Dog after_validation { false } - after_validation { self.history << 'after_validation_marker' } + after_validation { self.history << "after_validation_marker" } end class DogWithMissingName < Dog - before_validation { self.history << 'before_validation_marker' } + before_validation { self.history << "before_validation_marker" } validates_presence_of :name end @@ -53,8 +53,8 @@ class DogValidatorWithOnCondition < Dog before_validation :set_before_validation_marker, on: :create after_validation :set_after_validation_marker, on: :create - def set_before_validation_marker; self.history << 'before_validation_marker'; end - def set_after_validation_marker; self.history << 'after_validation_marker' ; end + def set_before_validation_marker; self.history << "before_validation_marker"; end + def set_after_validation_marker; self.history << "after_validation_marker" ; end end class DogValidatorWithIfCondition < Dog @@ -64,16 +64,15 @@ class DogValidatorWithIfCondition < Dog after_validation :set_after_validation_marker1, if: -> { true } after_validation :set_after_validation_marker2, if: -> { false } - def set_before_validation_marker1; self.history << 'before_validation_marker1'; end - def set_before_validation_marker2; self.history << 'before_validation_marker2' ; end + def set_before_validation_marker1; self.history << "before_validation_marker1"; end + def set_before_validation_marker2; self.history << "before_validation_marker2" ; end - def set_after_validation_marker1; self.history << 'after_validation_marker1'; end - def set_after_validation_marker2; self.history << 'after_validation_marker2' ; end + def set_after_validation_marker1; self.history << "after_validation_marker1"; end + def set_after_validation_marker2; self.history << "after_validation_marker2" ; end end class CallbacksWithMethodNamesShouldBeCalled < ActiveModel::TestCase - def test_if_condition_is_respected_for_before_validation d = DogValidatorWithIfCondition.new d.valid? @@ -101,19 +100,19 @@ class CallbacksWithMethodNamesShouldBeCalled < ActiveModel::TestCase def test_before_validation_and_after_validation_callbacks_should_be_called d = DogWithMethodCallbacks.new d.valid? - assert_equal ['before_validation_marker', 'after_validation_marker'], d.history + assert_equal ["before_validation_marker", "after_validation_marker"], d.history end def test_before_validation_and_after_validation_callbacks_should_be_called_with_proc d = DogValidatorsAreProc.new d.valid? - assert_equal ['before_validation_marker', 'after_validation_marker'], d.history + assert_equal ["before_validation_marker", "after_validation_marker"], d.history end def test_before_validation_and_after_validation_callbacks_should_be_called_in_declared_order d = DogWithTwoValidators.new d.valid? - assert_equal ['before_validation_marker1', 'before_validation_marker2'], d.history + assert_equal ["before_validation_marker1", "before_validation_marker2"], d.history end def test_further_callbacks_should_not_be_called_if_before_validation_throws_abort @@ -135,14 +134,13 @@ class CallbacksWithMethodNamesShouldBeCalled < ActiveModel::TestCase def test_further_callbacks_should_be_called_if_after_validation_returns_false d = DogAfterValidatorReturningFalse.new d.valid? - assert_equal ['after_validation_marker'], d.history + assert_equal ["after_validation_marker"], d.history end def test_validation_test_should_be_done d = DogWithMissingName.new output = d.valid? - assert_equal ['before_validation_marker'], d.history + assert_equal ["before_validation_marker"], d.history assert_equal false, output end - end |