@@ -62,13 +62,17 @@ def set_after_validation_marker; history << "after_validation_marker" ; end
62
62
class DogValidatorWithOnMultipleCondition < Dog
63
63
before_validation :set_before_validation_marker_on_context_a , on : :context_a
64
64
before_validation :set_before_validation_marker_on_context_b , on : :context_b
65
+ before_validation :set_before_validation_marker_except_on_context_a , except_on : :context_a
65
66
after_validation :set_after_validation_marker_on_context_a , on : :context_a
66
67
after_validation :set_after_validation_marker_on_context_b , on : :context_b
68
+ after_validation :set_after_validation_marker_except_on_context_a , except_on : :context_a
67
69
68
70
def set_before_validation_marker_on_context_a ; history << "before_validation_marker on context_a" ; end
69
71
def set_before_validation_marker_on_context_b ; history << "before_validation_marker on context_b" ; end
72
+ def set_before_validation_marker_except_on_context_a ; history << "before_validation_marker except on context_a" ; end
70
73
def set_after_validation_marker_on_context_a ; history << "after_validation_marker on context_a" ; end
71
74
def set_after_validation_marker_on_context_b ; history << "after_validation_marker on context_b" ; end
75
+ def set_after_validation_marker_except_on_context_a ; history << "after_validation_marker except on context_a" ; end
72
76
end
73
77
74
78
class DogValidatorWithIfCondition < Dog
@@ -117,7 +121,12 @@ def test_on_multiple_condition_is_respected_for_validation_with_matching_context
117
121
118
122
d = DogValidatorWithOnMultipleCondition . new
119
123
d . valid? ( :context_b )
120
- assert_equal [ "before_validation_marker on context_b" , "after_validation_marker on context_b" ] , d . history
124
+ assert_equal [
125
+ "before_validation_marker on context_b" ,
126
+ "before_validation_marker except on context_a" ,
127
+ "after_validation_marker on context_b" ,
128
+ "after_validation_marker except on context_a"
129
+ ] , d . history
121
130
122
131
d = DogValidatorWithOnMultipleCondition . new
123
132
d . valid? ( [ :context_a , :context_b ] )
@@ -132,13 +141,13 @@ def test_on_multiple_condition_is_respected_for_validation_with_matching_context
132
141
def test_on_multiple_condition_is_respected_for_validation_without_matching_context
133
142
d = DogValidatorWithOnMultipleCondition . new
134
143
d . valid? ( :save )
135
- assert_equal [ ] , d . history
144
+ assert_equal [ "before_validation_marker except on context_a" , "after_validation_marker except on context_a" ] , d . history
136
145
end
137
146
138
147
def test_on_multiple_condition_is_respected_for_validation_without_context
139
148
d = DogValidatorWithOnMultipleCondition . new
140
149
d . valid?
141
- assert_equal [ ] , d . history
150
+ assert_equal [ "before_validation_marker except on context_a" , "after_validation_marker except on context_a" ] , d . history
142
151
end
143
152
144
153
def test_before_validation_and_after_validation_callbacks_should_be_called
0 commit comments