How do I reload an ActiveRecord model class in a unit test? (In Ruby on Rails version 1.2.6)
I have a unit test that runs OK when run in isolation, such as rake test:recent RAILS_ENV=test.
The unit test will fail when run with all other unit tests, such as rake test:units RAILS_ENV=test.
The unit test that fails has a lot of ActiveRecord relationships with other models… models that need to get reloaded before I run the failing unit test. How do I do this?
Update
I found a way to work around the assertation failures without having to reload my data model. Tests now run OK in isolation or together.
You shouldn’t have dependencies in your tests like this in the first place, so this is probably a mistake. There are occasions you may need to reload models within your tests, but each test should be entirely independent and should leave the system in an acceptably consistent state.
The transaction system used by default for unit tests is supposed to revert any changes you have made to records, and because of this you should not be sharing data between different test methods.
Is there something specific you’re doing you think might be problematic?