Skip to content

Commit 801baee

Browse files
Use the new clear_validators! api to reset validators in tests
1 parent 5336ce2 commit 801baee

16 files changed

+33
-42
lines changed

activemodel/test/cases/validations/absence_validation_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
class AbsenceValidationTest < ActiveModel::TestCase
88
teardown do
9-
Topic.reset_callbacks(:validate)
10-
Person.reset_callbacks(:validate)
11-
CustomReader.reset_callbacks(:validate)
9+
Topic.clear_validators!
10+
Person.clear_validators!
11+
CustomReader.clear_validators!
1212
end
1313

1414
def test_validate_absences

activemodel/test/cases/validations/acceptance_validation_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class AcceptanceValidationTest < ActiveModel::TestCase
99

1010
def teardown
11-
Topic.reset_callbacks(:validate)
11+
Topic.clear_validators!
1212
end
1313

1414
def test_terms_of_service_agreement_no_acceptance

activemodel/test/cases/validations/conditional_validation_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class ConditionalValidationTest < ActiveModel::TestCase
77

88
def teardown
9-
Topic.reset_callbacks(:validate)
9+
Topic.clear_validators!
1010
end
1111

1212
def test_if_validation_using_method_true

activemodel/test/cases/validations/confirmation_validation_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class ConfirmationValidationTest < ActiveModel::TestCase
88

99
def teardown
10-
Topic.reset_callbacks(:validate)
10+
Topic.clear_validators!
1111
end
1212

1313
def test_no_title_confirmation
@@ -49,7 +49,7 @@ def test_validates_confirmation_of_for_ruby_class
4949
p.karma = "None"
5050
assert p.valid?
5151
ensure
52-
Person.reset_callbacks(:validate)
52+
Person.clear_validators!
5353
end
5454

5555
def test_title_confirmation_with_i18n_attribute

activemodel/test/cases/validations/exclusion_validation_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class ExclusionValidationTest < ActiveModel::TestCase
88

99
def teardown
10-
Topic.reset_callbacks(:validate)
10+
Topic.clear_validators!
1111
end
1212

1313
def test_validates_exclusion_of
@@ -50,7 +50,7 @@ def test_validates_exclusion_of_for_ruby_class
5050
p.karma = "Lifo"
5151
assert p.valid?
5252
ensure
53-
Person.reset_callbacks(:validate)
53+
Person.clear_validators!
5454
end
5555

5656
def test_validates_exclusion_of_with_lambda
@@ -87,6 +87,6 @@ def p.reserved_karmas
8787

8888
assert p.valid?
8989
ensure
90-
Person.reset_callbacks(:validate)
90+
Person.clear_validators!
9191
end
9292
end

activemodel/test/cases/validations/format_validation_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class PresenceValidationTest < ActiveModel::TestCase
88

99
def teardown
10-
Topic.reset_callbacks(:validate)
10+
Topic.clear_validators!
1111
end
1212

1313
def test_validate_format
@@ -68,11 +68,11 @@ def test_validate_format_with_formatted_message
6868
assert t.invalid?
6969
assert_equal ["can't be Invalid title"], t.errors[:title]
7070
end
71-
71+
7272
def test_validate_format_of_with_multiline_regexp_should_raise_error
7373
assert_raise(ArgumentError) { Topic.validates_format_of(:title, with: /^Valid Title$/) }
7474
end
75-
75+
7676
def test_validate_format_of_with_multiline_regexp_and_option
7777
assert_nothing_raised(ArgumentError) do
7878
Topic.validates_format_of(:title, with: /^Valid Title$/, multiline: true)
@@ -144,6 +144,6 @@ def test_validates_format_of_for_ruby_class
144144
p.karma = "1234"
145145
assert p.valid?
146146
ensure
147-
Person.reset_callbacks(:validate)
147+
Person.clear_validators!
148148
end
149149
end

activemodel/test/cases/validations/i18n_generate_message_validation_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class I18nGenerateMessageValidationTest < ActiveModel::TestCase
66
def setup
7-
Person.reset_callbacks(:validate)
7+
Person.clear_validators!
88
@person = Person.new
99
end
1010

activemodel/test/cases/validations/i18n_validation_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class I18nValidationTest < ActiveModel::TestCase
77

88
def setup
9-
Person.reset_callbacks(:validate)
9+
Person.clear_validators!
1010
@person = Person.new
1111

1212
@old_load_path, @old_backend = I18n.load_path.dup, I18n.backend
@@ -16,7 +16,7 @@ def setup
1616
end
1717

1818
def teardown
19-
Person.reset_callbacks(:validate)
19+
Person.clear_validators!
2020
I18n.load_path.replace @old_load_path
2121
I18n.backend = @old_backend
2222
end

activemodel/test/cases/validations/inclusion_validation_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class InclusionValidationTest < ActiveModel::TestCase
99

1010
def teardown
11-
Topic.reset_callbacks(:validate)
11+
Topic.clear_validators!
1212
end
1313

1414
def test_validates_inclusion_of_range
@@ -105,7 +105,7 @@ def test_validates_inclusion_of_for_ruby_class
105105
p.karma = "monkey"
106106
assert p.valid?
107107
ensure
108-
Person.reset_callbacks(:validate)
108+
Person.clear_validators!
109109
end
110110

111111
def test_validates_inclusion_of_with_lambda
@@ -142,6 +142,6 @@ def p.available_karmas
142142

143143
assert p.valid?
144144
ensure
145-
Person.reset_callbacks(:validate)
145+
Person.clear_validators!
146146
end
147147
end

activemodel/test/cases/validations/length_validation_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class LengthValidationTest < ActiveModel::TestCase
88
def teardown
9-
Topic.reset_callbacks(:validate)
9+
Topic.clear_validators!
1010
end
1111

1212
def test_validates_length_of_with_allow_nil
@@ -354,7 +354,7 @@ def test_validates_length_of_for_ruby_class
354354
p.karma = "The Smiths"
355355
assert p.valid?
356356
ensure
357-
Person.reset_callbacks(:validate)
357+
Person.clear_validators!
358358
end
359359

360360
def test_validates_length_of_for_infinite_maxima

activemodel/test/cases/validations/numericality_validation_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class NumericalityValidationTest < ActiveModel::TestCase
1010

1111
def teardown
12-
Topic.reset_callbacks(:validate)
12+
Topic.clear_validators!
1313
end
1414

1515
NIL = [nil]
@@ -157,7 +157,7 @@ def test_validates_numericality_of_for_ruby_class
157157
p.karma = "1234"
158158
assert p.valid?
159159
ensure
160-
Person.reset_callbacks(:validate)
160+
Person.clear_validators!
161161
end
162162

163163
def test_validates_numericality_with_invalid_args

activemodel/test/cases/validations/presence_validation_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
class PresenceValidationTest < ActiveModel::TestCase
99

1010
teardown do
11-
Topic.reset_callbacks(:validate)
12-
Person.reset_callbacks(:validate)
13-
CustomReader.reset_callbacks(:validate)
11+
Topic.clear_validators!
12+
Person.clear_validators!
13+
CustomReader.clear_validators!
1414
end
1515

1616
def test_validate_presences

activemodel/test/cases/validations/validates_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class ValidatesTest < ActiveModel::TestCase
1111
teardown :reset_callbacks
1212

1313
def reset_callbacks
14-
Person.reset_callbacks(:validate)
15-
Topic.reset_callbacks(:validate)
16-
PersonWithValidator.reset_callbacks(:validate)
14+
Person.clear_validators!
15+
Topic.clear_validators!
16+
PersonWithValidator.clear_validators!
1717
end
1818

1919
def test_validates_with_messages_empty

activemodel/test/cases/validations/validations_context_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
class ValidationsContextTest < ActiveModel::TestCase
77
def teardown
8-
Topic.reset_callbacks(:validate)
9-
Topic._validators.clear
8+
Topic.clear_validators!
109
end
1110

1211
ERROR_MESSAGE = "Validation error from validator"

activemodel/test/cases/validations/with_validation_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
class ValidatesWithTest < ActiveModel::TestCase
77

88
def teardown
9-
Topic.reset_callbacks(:validate)
10-
Topic._validators.clear
9+
Topic.clear_validators!
1110
end
1211

1312
ERROR_MESSAGE = "Validation error from validator"

activemodel/test/cases/validations_test.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,10 @@
1010
require 'active_support/xml_mini'
1111

1212
class ValidationsTest < ActiveModel::TestCase
13-
1413
class CustomStrictValidationException < StandardError; end
1514

16-
def setup
17-
Topic._validators.clear
18-
end
19-
20-
# Most of the tests mess with the validations of Topic, so lets repair it all the time.
21-
# Other classes we mess with will be dealt with in the specific tests
2215
def teardown
23-
Topic.reset_callbacks(:validate)
16+
Topic.clear_validators!
2417
end
2518

2619
def test_single_field_validation

0 commit comments

Comments
 (0)