When I run a task that should be running in the test environment, it is running in development. This includes rake test:(units/functionals/integration)
and rake db:test:prepare
. A side effect is that it is overwriting my database every time I run tests. I renamed the development database, and now it keeps complaining that it can't find my old database (the one in database.yml
). The environment is being set to development in require 'rails'
at the top of my application.rb
. Am I missing some sort of simple configuration?
Edit: If I run my tests appended with RAILS_ENV=test
, they are run in the test environment. However, I can't actually run them because I have pending migrations (all of them). Running rake db:test:prepare RAILS_ENV=test
gives me the same pending-migrations error.
Update: The database is migrated, and my tests are going. I still feel like running my tests every time with RAILS_ENV=test
isn't the correct way to be doing it
Update: I found that if I change def env
in railties to default to 'test', the environment becomes test. That is
def env
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
end