The documentation on fixtures makes a tantalizing claim:
| If you preload your test database with all fixture data
| (probably in the Rakefile task) and use transactional
| fixtures, then you may omit all fixtures declarations
| in your test cases since all the dataâ€™s already there
| and every case rolls back its changes.
Yup! That’s exactly what I want: I have some LARGE constant tables that
are used pervasively, so I want to load them ONCE and exploit the
efficiency of transactional fixtures thereafter. I know I can preload
the test database from fixtures like this:
% rake db:fixtures:load RAILS_ENV=test
But then how do I run unit tests while preserving my carefully preloaded
I know I can’t simply use ‘rake test:units’, defined as:
Rake::TestTask.new(:units => “db:test:prepare”) do |t|
t.libs << “test”
t.pattern = ‘test/unit/**/*_test.rb’
t.verbose = true
Rake::Task[‘test:units’].comment = “Run the unit tests in test/unit”
The dependency on “db:test:prepare” clears the database. I could define
a rake task “test:units_without_blowing_away_my_data_please” that
eliminates that dependency, or perhaps better, a define a task that
loads the fixtures before running the unit tests.
But the comment in the fixture documentation makes me think that there’s
an easier way. Is there?