diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2013-04-21 11:34:12 -0400 |
---|---|---|
committer | Neeraj Singh <neerajdotname@gmail.com> | 2013-04-21 11:34:12 -0400 |
commit | cf69d527feb9faadb7feb7afcc1c0d5cd5e6f77a (patch) | |
tree | cf5b02efda3fa1b4154feb5449f4e8370ed9cbe1 /activemodel | |
parent | a489bfe48bc0fbbb50a472bc66bd42d408c73fcb (diff) | |
download | rails-cf69d527feb9faadb7feb7afcc1c0d5cd5e6f77a.tar.gz rails-cf69d527feb9faadb7feb7afcc1c0d5cd5e6f77a.tar.bz2 rails-cf69d527feb9faadb7feb7afcc1c0d5cd5e6f77a.zip |
Added tests for if condition in Active Model callbacks
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/test/cases/validations/callbacks_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/callbacks_test.rb b/activemodel/test/cases/validations/callbacks_test.rb index 0015b3c196..6cd0f4ed4d 100644 --- a/activemodel/test/cases/validations/callbacks_test.rb +++ b/activemodel/test/cases/validations/callbacks_test.rb @@ -40,8 +40,29 @@ class DogWithMissingName < Dog validates_presence_of :name end +class DogValidatorWithIfCondition < Dog + before_validation :set_before_validation_marker1, if: -> { true } + before_validation :set_before_validation_marker2, if: -> { false } + + 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_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? + assert_equal ["before_validation_marker1", "after_validation_marker1"], d.history + end + def test_before_validation_and_after_validation_callbacks_should_be_called d = DogWithMethodCallbacks.new d.valid? |