1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use the new clear_validators! api to reset validators in tests

This commit is contained in:
Carlos Antonio da Silva 2014-01-27 08:22:26 -02:00
parent 5336ce265a
commit 801baeed69
16 changed files with 33 additions and 42 deletions

View file

@ -6,9 +6,9 @@ require 'models/custom_reader'
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

View file

@ -8,7 +8,7 @@ require 'models/person'
class AcceptanceValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_terms_of_service_agreement_no_acceptance

View file

@ -6,7 +6,7 @@ require 'models/topic'
class ConditionalValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_if_validation_using_method_true

View file

@ -7,7 +7,7 @@ require 'models/person'
class ConfirmationValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_no_title_confirmation
@ -49,7 +49,7 @@ class ConfirmationValidationTest < ActiveModel::TestCase
p.karma = "None"
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
def test_title_confirmation_with_i18n_attribute

View file

@ -7,7 +7,7 @@ require 'models/person'
class ExclusionValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_validates_exclusion_of
@ -50,7 +50,7 @@ class ExclusionValidationTest < ActiveModel::TestCase
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 @@ class ExclusionValidationTest < ActiveModel::TestCase
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
end

View file

@ -7,7 +7,7 @@ require 'models/person'
class PresenceValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_validate_format
@ -68,11 +68,11 @@ class PresenceValidationTest < ActiveModel::TestCase
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 @@ class PresenceValidationTest < ActiveModel::TestCase
p.karma = "1234"
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
end

View file

@ -4,7 +4,7 @@ require 'models/person'
class I18nGenerateMessageValidationTest < ActiveModel::TestCase
def setup
Person.reset_callbacks(:validate)
Person.clear_validators!
@person = Person.new
end

View file

@ -6,7 +6,7 @@ require 'models/person'
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 @@ class I18nValidationTest < ActiveModel::TestCase
end
def teardown
Person.reset_callbacks(:validate)
Person.clear_validators!
I18n.load_path.replace @old_load_path
I18n.backend = @old_backend
end

View file

@ -8,7 +8,7 @@ require 'models/person'
class InclusionValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
def test_validates_inclusion_of_range
@ -105,7 +105,7 @@ class InclusionValidationTest < ActiveModel::TestCase
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 @@ class InclusionValidationTest < ActiveModel::TestCase
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
end

View file

@ -6,7 +6,7 @@ require 'models/person'
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 @@ class LengthValidationTest < ActiveModel::TestCase
p.karma = "The Smiths"
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
def test_validates_length_of_for_infinite_maxima

View file

@ -9,7 +9,7 @@ require 'bigdecimal'
class NumericalityValidationTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic.clear_validators!
end
NIL = [nil]
@ -157,7 +157,7 @@ class NumericalityValidationTest < ActiveModel::TestCase
p.karma = "1234"
assert p.valid?
ensure
Person.reset_callbacks(:validate)
Person.clear_validators!
end
def test_validates_numericality_with_invalid_args

View file

@ -8,9 +8,9 @@ require 'models/custom_reader'
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

View file

@ -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

View file

@ -5,8 +5,7 @@ require 'models/topic'
class ValidationsContextTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic._validators.clear
Topic.clear_validators!
end
ERROR_MESSAGE = "Validation error from validator"

View file

@ -6,8 +6,7 @@ require 'models/topic'
class ValidatesWithTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic._validators.clear
Topic.clear_validators!
end
ERROR_MESSAGE = "Validation error from validator"

View file

@ -10,17 +10,10 @@ require 'active_support/json'
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