mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #10284 from neerajdotname/missing-active-model-tests
Added tests for if condition in Active Model callbacks
This commit is contained in:
commit
52ba5a5bec
1 changed files with 21 additions and 0 deletions
|
@ -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?
|
||||
|
|
Loading…
Reference in a new issue