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

Use the new clear_validators! api to reset validators in tests

上级 5336ce26
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
class AbsenceValidationTest < ActiveModel::TestCase class AbsenceValidationTest < ActiveModel::TestCase
teardown do teardown do
Topic.reset_callbacks(:validate) Topic.clear_validators!
Person.reset_callbacks(:validate) Person.clear_validators!
CustomReader.reset_callbacks(:validate) CustomReader.clear_validators!
end end
def test_validate_absences def test_validate_absences
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
class AcceptanceValidationTest < ActiveModel::TestCase class AcceptanceValidationTest < ActiveModel::TestCase
def teardown def teardown
Topic.reset_callbacks(:validate) Topic.clear_validators!
end end
def test_terms_of_service_agreement_no_acceptance def test_terms_of_service_agreement_no_acceptance
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
class ConditionalValidationTest < ActiveModel::TestCase class ConditionalValidationTest < ActiveModel::TestCase
def teardown def teardown
Topic.reset_callbacks(:validate) Topic.clear_validators!
end end
def test_if_validation_using_method_true def test_if_validation_using_method_true
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
class ConfirmationValidationTest < ActiveModel::TestCase class ConfirmationValidationTest < ActiveModel::TestCase
def teardown def teardown
Topic.reset_callbacks(:validate) Topic.clear_validators!
end end
def test_no_title_confirmation def test_no_title_confirmation
...@@ -49,7 +49,7 @@ def test_validates_confirmation_of_for_ruby_class ...@@ -49,7 +49,7 @@ def test_validates_confirmation_of_for_ruby_class
p.karma = "None" p.karma = "None"
assert p.valid? assert p.valid?
ensure ensure
Person.reset_callbacks(:validate) Person.clear_validators!
end end
def test_title_confirmation_with_i18n_attribute def test_title_confirmation_with_i18n_attribute
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
class ExclusionValidationTest < ActiveModel::TestCase class ExclusionValidationTest < ActiveModel::TestCase
def teardown def teardown
Topic.reset_callbacks(:validate) Topic.clear_validators!
end end
def test_validates_exclusion_of def test_validates_exclusion_of
...@@ -50,7 +50,7 @@ def test_validates_exclusion_of_for_ruby_class ...@@ -50,7 +50,7 @@ def test_validates_exclusion_of_for_ruby_class
p.karma = "Lifo" p.karma = "Lifo"
assert p.valid? assert p.valid?
ensure ensure
Person.reset_callbacks(:validate) Person.clear_validators!
end end
def test_validates_exclusion_of_with_lambda def test_validates_exclusion_of_with_lambda
...@@ -87,6 +87,6 @@ def p.reserved_karmas ...@@ -87,6 +87,6 @@ def p.reserved_karmas
assert p.valid? assert p.valid?
ensure ensure
Person.reset_callbacks(:validate) Person.clear_validators!
end end
end end
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
class PresenceValidationTest < ActiveModel::TestCase class PresenceValidationTest < ActiveModel::TestCase
def teardown def teardown
Topic.reset_callbacks(:validate) Topic.clear_validators!
end end
def test_validate_format def test_validate_format
...@@ -144,6 +144,6 @@ def test_validates_format_of_for_ruby_class ...@@ -144,6 +144,6 @@ def test_validates_format_of_for_ruby_class
p.karma = "1234" p.karma = "1234"
assert p.valid? assert p.valid?
ensure ensure
Person.reset_callbacks(:validate) Person.clear_validators!
end end
end end
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
class I18nGenerateMessageValidationTest < ActiveModel::TestCase class I18nGenerateMessageValidationTest < ActiveModel::TestCase
def setup def setup
Person.reset_callbacks(:validate) Person.clear_validators!
@person = Person.new @person = Person.new
end end
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
class I18nValidationTest < ActiveModel::TestCase class I18nValidationTest < ActiveModel::TestCase
def setup def setup
Person.reset_callbacks(:validate) Person.clear_validators!
@person = Person.new @person = Person.new
@old_load_path, @old_backend = I18n.load_path.dup, I18n.backend @old_load_path, @old_backend = I18n.load_path.dup, I18n.backend
...@@ -16,7 +16,7 @@ def setup ...@@ -16,7 +16,7 @@ def setup
end end
def teardown def teardown
Person.reset_callbacks(:validate) Person.clear_validators!
I18n.load_path.replace @old_load_path I18n.load_path.replace @old_load_path
I18n.backend = @old_backend I18n.backend = @old_backend
end end
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
class InclusionValidationTest < ActiveModel::TestCase class InclusionValidationTest < ActiveModel::TestCase
def teardown def teardown
Topic.reset_callbacks(:validate) Topic.clear_validators!
end end
def test_validates_inclusion_of_range def test_validates_inclusion_of_range
...@@ -105,7 +105,7 @@ def test_validates_inclusion_of_for_ruby_class ...@@ -105,7 +105,7 @@ def test_validates_inclusion_of_for_ruby_class
p.karma = "monkey" p.karma = "monkey"
assert p.valid? assert p.valid?
ensure ensure
Person.reset_callbacks(:validate) Person.clear_validators!
end end
def test_validates_inclusion_of_with_lambda def test_validates_inclusion_of_with_lambda
...@@ -142,6 +142,6 @@ def p.available_karmas ...@@ -142,6 +142,6 @@ def p.available_karmas
assert p.valid? assert p.valid?
ensure ensure
Person.reset_callbacks(:validate) Person.clear_validators!
end end
end end
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
class LengthValidationTest < ActiveModel::TestCase class LengthValidationTest < ActiveModel::TestCase
def teardown def teardown
Topic.reset_callbacks(:validate) Topic.clear_validators!
end end
def test_validates_length_of_with_allow_nil def test_validates_length_of_with_allow_nil
...@@ -354,7 +354,7 @@ def test_validates_length_of_for_ruby_class ...@@ -354,7 +354,7 @@ def test_validates_length_of_for_ruby_class
p.karma = "The Smiths" p.karma = "The Smiths"
assert p.valid? assert p.valid?
ensure ensure
Person.reset_callbacks(:validate) Person.clear_validators!
end end
def test_validates_length_of_for_infinite_maxima def test_validates_length_of_for_infinite_maxima
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
class NumericalityValidationTest < ActiveModel::TestCase class NumericalityValidationTest < ActiveModel::TestCase
def teardown def teardown
Topic.reset_callbacks(:validate) Topic.clear_validators!
end end
NIL = [nil] NIL = [nil]
...@@ -157,7 +157,7 @@ def test_validates_numericality_of_for_ruby_class ...@@ -157,7 +157,7 @@ def test_validates_numericality_of_for_ruby_class
p.karma = "1234" p.karma = "1234"
assert p.valid? assert p.valid?
ensure ensure
Person.reset_callbacks(:validate) Person.clear_validators!
end end
def test_validates_numericality_with_invalid_args def test_validates_numericality_with_invalid_args
......
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
class PresenceValidationTest < ActiveModel::TestCase class PresenceValidationTest < ActiveModel::TestCase
teardown do teardown do
Topic.reset_callbacks(:validate) Topic.clear_validators!
Person.reset_callbacks(:validate) Person.clear_validators!
CustomReader.reset_callbacks(:validate) CustomReader.clear_validators!
end end
def test_validate_presences def test_validate_presences
......
...@@ -11,9 +11,9 @@ class ValidatesTest < ActiveModel::TestCase ...@@ -11,9 +11,9 @@ class ValidatesTest < ActiveModel::TestCase
teardown :reset_callbacks teardown :reset_callbacks
def reset_callbacks def reset_callbacks
Person.reset_callbacks(:validate) Person.clear_validators!
Topic.reset_callbacks(:validate) Topic.clear_validators!
PersonWithValidator.reset_callbacks(:validate) PersonWithValidator.clear_validators!
end end
def test_validates_with_messages_empty def test_validates_with_messages_empty
......
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
class ValidationsContextTest < ActiveModel::TestCase class ValidationsContextTest < ActiveModel::TestCase
def teardown def teardown
Topic.reset_callbacks(:validate) Topic.clear_validators!
Topic._validators.clear
end end
ERROR_MESSAGE = "Validation error from validator" ERROR_MESSAGE = "Validation error from validator"
......
...@@ -6,8 +6,7 @@ ...@@ -6,8 +6,7 @@
class ValidatesWithTest < ActiveModel::TestCase class ValidatesWithTest < ActiveModel::TestCase
def teardown def teardown
Topic.reset_callbacks(:validate) Topic.clear_validators!
Topic._validators.clear
end end
ERROR_MESSAGE = "Validation error from validator" ERROR_MESSAGE = "Validation error from validator"
......
...@@ -10,17 +10,10 @@ ...@@ -10,17 +10,10 @@
require 'active_support/xml_mini' require 'active_support/xml_mini'
class ValidationsTest < ActiveModel::TestCase class ValidationsTest < ActiveModel::TestCase
class CustomStrictValidationException < StandardError; end 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 def teardown
Topic.reset_callbacks(:validate) Topic.clear_validators!
end end
def test_single_field_validation def test_single_field_validation
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册