Override RAILS_ENV from rake task

I have a bunch of rake tasks that work against whichever database is
associated with the current RAILS_ENV. But there is another rake task
that I want to invoke those db neutral tasks from that should only ever
work against the test database.

How do I override RAILS_ENV before invoking the database neutral tasks?

Thanks!

-b

You could do

rake RAILS_ENV=“test” taskname

or are you looking for something more programmable?

Brian H. wrote:

You could do

rake RAILS_ENV=“test” taskname

or are you looking for something more programmable?

More programmable. I noticed in looking the standard Rails test tasks
that they aren’t very DRY. There are a couple of places where code is
repeated from the db namespace tasks apparently just to solve this
problem.

Bryan Wilkerson wrote:

I have a bunch of rake tasks that work against whichever database is
associated with the current RAILS_ENV. But there is another rake task
that I want to invoke those db neutral tasks from that should only ever
work against the test database.

How do I override RAILS_ENV before invoking the database neutral tasks?

Thanks!

-b

I take back what I said about the test tasks. One of them provided me
with the answer - you have to just set the connection.
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[‘test’])