From 74098e4cb6de01745db8f1d8d567645553ade7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 23 Dec 2009 13:30:58 +0100 Subject: No need to use ValidationsRepairHelper hack on ActiveModel anymore, Model.reset_callbacks(:validate) is enough. However, tests in ActiveRecord are still coupled, so moved ValidationsRepairHelper back there. --- .../cases/validations/format_validation_test.rb | 33 ++++++++-------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'activemodel/test/cases/validations/format_validation_test.rb') diff --git a/activemodel/test/cases/validations/format_validation_test.rb b/activemodel/test/cases/validations/format_validation_test.rb index e19e4bf7b3..e10089208a 100644 --- a/activemodel/test/cases/validations/format_validation_test.rb +++ b/activemodel/test/cases/validations/format_validation_test.rb @@ -8,9 +8,10 @@ require 'models/person' class PresenceValidationTest < ActiveModel::TestCase include ActiveModel::TestsDatabase - include ActiveModel::ValidationsRepairHelper - repair_validations(Topic) + def teardown + Topic.reset_callbacks(:validate) + end def test_validate_format Topic.validates_format_of(:title, :content, :with => /^Validation\smacros \w+!$/, :message => "is bad data") @@ -100,28 +101,18 @@ class PresenceValidationTest < ActiveModel::TestCase assert_raise(ArgumentError) { Topic.validates_format_of(:title, :without => "clearly not a regexp") } end - def test_validates_format_of_with_custom_error_using_quotes - repair_validations(Developer) do - Developer.validates_format_of :name, :with => /^(A-Z*)$/, :message=> "format 'single' and \"double\" quotes" - d = Developer.new - d.name = d.name_confirmation = "John 32" - assert !d.valid? - assert_equal ["format 'single' and \"double\" quotes"], d.errors[:name] - end - end - def test_validates_format_of_for_ruby_class - repair_validations(Person) do - Person.validates_format_of :karma, :with => /\A\d+\Z/ + Person.validates_format_of :karma, :with => /\A\d+\Z/ - p = Person.new - p.karma = "Pixies" - assert p.invalid? + p = Person.new + p.karma = "Pixies" + assert p.invalid? - assert_equal ["is invalid"], p.errors[:karma] + assert_equal ["is invalid"], p.errors[:karma] - p.karma = "1234" - assert p.valid? - end + p.karma = "1234" + assert p.valid? + ensure + Person.reset_callbacks(:validate) end end -- cgit v1.2.3