提交 801baeed 编写于 作者: C Carlos Antonio da Silva

Use the new clear_validators! api to reset validators in tests

上级 5336ce26
......@@ -6,9 +6,9 @@
class AbsenceValidationTest < ActiveModel::TestCase
teardown do
Topic.reset_callbacks(:validate)
Person.reset_callbacks(:validate)
CustomReader.reset_callbacks(:validate)
Topic.clear_validators!
Person.clear_validators!
CustomReader.clear_validators!
end
def test_validate_absences
......
......@@ -8,7 +8,7 @@
class AcceptanceValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_terms_of_service_agreement_no_acceptance
......
......@@ -6,7 +6,7 @@
class ConditionalValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_if_validation_using_method_true
......
......@@ -7,7 +7,7 @@
class ConfirmationValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_no_title_confirmation
......@@ -49,7 +49,7 @@ def test_validates_confirmation_of_for_ruby_class
p.karma = "None"
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
def test_title_confirmation_with_i18n_attribute
......
......@@ -7,7 +7,7 @@
class ExclusionValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_validates_exclusion_of
......@@ -50,7 +50,7 @@ def test_validates_exclusion_of_for_ruby_class
p.karma = "Lifo"
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
def test_validates_exclusion_of_with_lambda
......@@ -87,6 +87,6 @@ def p.reserved_karmas
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
end
......@@ -7,7 +7,7 @@
class PresenceValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_validate_format
......@@ -68,11 +68,11 @@ def test_validate_format_with_formatted_message
assert t.invalid?
assert_equal ["can't be Invalid title"], t.errors[:title]
end
def test_validate_format_of_with_multiline_regexp_should_raise_error
assert_raise(ArgumentError) { Topic.validates_format_of(:title, with: /^Valid Title$/) }
end
def test_validate_format_of_with_multiline_regexp_and_option
assert_nothing_raised(ArgumentError) do
Topic.validates_format_of(:title, with: /^Valid Title$/, multiline: true)
......@@ -144,6 +144,6 @@ def test_validates_format_of_for_ruby_class
p.karma = "1234"
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
end
......@@ -4,7 +4,7 @@
class I18nGenerateMessageValidationTest < ActiveModel::TestCase
def setup
Person.reset_callbacks(:validate)
Person.clear_validators!
@person = Person.new
end
......
......@@ -6,7 +6,7 @@
class I18nValidationTest < ActiveModel::TestCase
def setup
Person.reset_callbacks(:validate)
Person.clear_validators!
@person = Person.new
@old_load_path, @old_backend = I18n.load_path.dup, I18n.backend
......@@ -16,7 +16,7 @@ def setup
end
def teardown
Person.reset_callbacks(:validate)
Person.clear_validators!
I18n.load_path.replace @old_load_path
I18n.backend = @old_backend
end
......
......@@ -8,7 +8,7 @@
class InclusionValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_validates_inclusion_of_range
......@@ -105,7 +105,7 @@ def test_validates_inclusion_of_for_ruby_class
p.karma = "monkey"
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
def test_validates_inclusion_of_with_lambda
......@@ -142,6 +142,6 @@ def p.available_karmas
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
end
......@@ -6,7 +6,7 @@
class LengthValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_validates_length_of_with_allow_nil
......@@ -354,7 +354,7 @@ def test_validates_length_of_for_ruby_class
p.karma = "The Smiths"
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
def test_validates_length_of_for_infinite_maxima
......
......@@ -9,7 +9,7 @@
class NumericalityValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
NIL = [nil]
......@@ -157,7 +157,7 @@ def test_validates_numericality_of_for_ruby_class
p.karma = "1234"
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
def test_validates_numericality_with_invalid_args
......
......@@ -8,9 +8,9 @@
class PresenceValidationTest < ActiveModel::TestCase
teardown do
Topic.reset_callbacks(:validate)
Person.reset_callbacks(:validate)
CustomReader.reset_callbacks(:validate)
Topic.clear_validators!
Person.clear_validators!
CustomReader.clear_validators!
end
def test_validate_presences
......
......@@ -11,9 +11,9 @@ class ValidatesTest < ActiveModel::TestCase
teardown :reset_callbacks
def reset_callbacks
Person.reset_callbacks(:validate)
Topic.reset_callbacks(:validate)
PersonWithValidator.reset_callbacks(:validate)
Person.clear_validators!
Topic.clear_validators!
PersonWithValidator.clear_validators!
end
def test_validates_with_messages_empty
......
......@@ -5,8 +5,7 @@
class ValidationsContextTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic._validators.clear
Topic.clear_validators!
end
ERROR_MESSAGE = "Validation error from validator"
......
......@@ -6,8 +6,7 @@
class ValidatesWithTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic._validators.clear
Topic.clear_validators!
end
ERROR_MESSAGE = "Validation error from validator"
......
......@@ -10,17 +10,10 @@
require 'active_support/xml_mini'
class ValidationsTest < ActiveModel::TestCase
class CustomStrictValidationException < StandardError; end
def setup
Topic._validators.clear
end
# Most of the tests mess with the validations of Topic, so lets repair it all the time.
# Other classes we mess with will be dealt with in the specific tests
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_single_field_validation
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册