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/length_validation_test.rb | 53 +++++----------------- 1 file changed, 12 insertions(+), 41 deletions(-) (limited to 'activemodel/test/cases/validations/length_validation_test.rb') diff --git a/activemodel/test/cases/validations/length_validation_test.rb b/activemodel/test/cases/validations/length_validation_test.rb index 2c97b762f1..f3ef5e648a 100644 --- a/activemodel/test/cases/validations/length_validation_test.rb +++ b/activemodel/test/cases/validations/length_validation_test.rb @@ -8,9 +8,10 @@ require 'models/person' class LengthValidationTest < ActiveModel::TestCase include ActiveModel::TestsDatabase - include ActiveModel::ValidationsRepairHelper - repair_validations(Topic) + def teardown + Topic.reset_callbacks(:validate) + end def test_validates_length_of_with_allow_nil Topic.validates_length_of( :title, :is => 5, :allow_nil=>true ) @@ -419,48 +420,18 @@ class LengthValidationTest < ActiveModel::TestCase assert_equal ["Your essay must be at least 5 words."], t.errors[:content] end - def test_validates_length_of_with_custom_too_long_using_quotes - repair_validations(Developer) do - Developer.validates_length_of :name, :maximum => 4, :too_long=> "This string contains 'single' and \"double\" quotes" - d = Developer.new - d.name = "Jeffrey" - assert !d.valid? - assert_equal ["This string contains 'single' and \"double\" quotes"], d.errors[:name] - end - end - - def test_validates_length_of_with_custom_too_short_using_quotes - repair_validations(Developer) do - Developer.validates_length_of :name, :minimum => 4, :too_short=> "This string contains 'single' and \"double\" quotes" - d = Developer.new - d.name = "Joe" - assert !d.valid? - assert_equal ["This string contains 'single' and \"double\" quotes"], d.errors[:name] - end - end - - def test_validates_length_of_with_custom_message_using_quotes - repair_validations(Developer) do - Developer.validates_length_of :name, :minimum => 4, :message=> "This string contains 'single' and \"double\" quotes" - d = Developer.new - d.name = "Joe" - assert !d.valid? - assert_equal ["This string contains 'single' and \"double\" quotes"], d.errors[:name] - end - end - def test_validates_length_of_for_ruby_class - repair_validations(Person) do - Person.validates_length_of :karma, :minimum => 5 + Person.validates_length_of :karma, :minimum => 5 - p = Person.new - p.karma = "Pix" - assert p.invalid? + p = Person.new + p.karma = "Pix" + assert p.invalid? - assert_equal ["is too short (minimum is 5 characters)"], p.errors[:karma] + assert_equal ["is too short (minimum is 5 characters)"], p.errors[:karma] - p.karma = "The Smiths" - assert p.valid? - end + p.karma = "The Smiths" + assert p.valid? + ensure + Person.reset_callbacks(:validate) end end -- cgit v1.2.3