Running custom SQL to prepare Rails integration test
I am trying to run some custom SQL during the setup of my Rails integration tests to prepare a legacy dat开发者_高级运维abase (e.g., to create its tables, create any required views, etc.), which is not part of my schema.rb (nor do any migrations for it exist).
Are there any best practices for doing so? Googling has not been very enlightening so far ;-)
The reason why there are not any migrations is that in the development and production RAILS_ENV
the database already exists for legacy reasons. If there is a way to run these migrations only for RAILS_ENV=='test'
, that would maybe also help.
You can pass the Rails environment to Rake on the command line. For example, to only run migrations for the test environment, do:
rake RAILS_ENV=test db:migrate
精彩评论