Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8218 (new defect)

Opened 1 year ago

Last modified 1 year ago

[PATCH] activerecord unit tests not cleaning up models between tests

Reported by: JakeB Assigned to: bitsweat
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: 1.2.3
Severity: normal Keywords:
Cc:

Description

I started this on the core mailing list, but I thought I'd open an issue too.

I'm trying to do a patch for Ticket #5369

I am working with the 1-2-stable branch. I was trying to add a test that adds validates_associated to the Reply model and goes for a false valid?. I discovered that it would only fail properly if I prepended 000 to the name so it would run early in the list of tests. I tracked down the problem to several tests adding various validations to the models. These validations are persistant across tests.

Here's what the validations of the Reply model look like during my test if I run my test at the begininning of the suite:

(rdb:1) pp validations
[#<Proc:0xb78d3e68@./../lib/active_record/validations.rb:296>,
 :errors_on_empty_content,
 :validate_associated_records_for_replies]

And here's what they look like if I break in the same test with only the name modified so it runs in the middle of the pack.

(rdb:1) pp validations
[#<Proc:0xb78c9e68@./../lib/active_record/validations.rb:296>,
 #<Proc:0xb78bda14@./../lib/active_record/validations.rb:407>,
 #<Proc:0xb78c9e68@./../lib/active_record/validations.rb:296>,
 #<Proc:0xb78c9e68@./../lib/active_record/validations.rb:296>,
 :errors_on_empty_content,
 :validate_associated_records_for_replies]

As you can see it has gathered a couple more validations from tests running in the first half of the suite.

I added some code to the setup method to reload the model classes used and uncovered some tests that depended on others running first to pass correctly. I corrected all of the tests that had problems after my modification. I'm not sure if the way I reload the models is the cleanest as I'm a ruby noob, but I thought I'd share it just in case it was useful.

Attachments

reload_models.patch (3.9 kB) - added by JakeB on 05/03/07 21:22:59.

Change History

04/29/07 14:23:25 changed by roderickvd

I've noticed this too. The CI build isn't picking up on some test failures exactly because of it. #7981 is an example of such a test.

05/03/07 21:22:59 changed by JakeB

  • attachment reload_models.patch added.

05/05/07 20:07:06 changed by watson

  • summary changed from activerecord unit tests not cleaning up models between tests to [PATCH] activerecord unit tests not cleaning up models between tests.

(follow-up: ↓ 4 ) 05/25/07 01:44:17 changed by bitsweat

  • owner changed from core to bitsweat.

That code in setup is supposed to clear existing validations.

Some of the other changes in this patch are odd, like

-    d.name = d.name_confirmation = "John 32"
+    d.name = d.name = "John 32"

(in reply to: ↑ 3 ) 05/25/07 15:11:26 changed by JakeB

Replying to bitsweat:

That code in setup is supposed to clear existing validations. Some of the other changes in this patch are odd, like {{{ - d.name = d.name_confirmation = "John 32" + d.name = d.name = "John 32" }}}

Some tests add a validates_confirmation_of, so other tests were setting the confirmation to get things to work. If all the validations are cleared between tests this no longer is necessary and actually causes breakages because *_confirmation is only defined if validates_confirmation_of is applied.