Skip to content

Commit

Permalink
Force RAILS_ENV to be "test" in rake tasks
Browse files Browse the repository at this point in the history
After #732, if you're using the SQL schema format, `parallel:prepare`
now calls `db:purge db:structure:load` where it used to call
`db:test:prepare`. The old task forced using the test environment,
however the new tasks make no assumptions about the environment.
Therefore, when combined with a Spring-ified rake binstub, where Spring
defaults to the development environment, when `parallel:prepare` calls
`db:purge db:structure:load`, they're running in the development
environment against the development database, instead of in the test
environment against the test database.

Now the environment is forced to be "test" in all rake tasks regardless
of the RAILS_ENV that might have been set, whether by Spring or the
user. This has the side-effect of removing the ability to run the tasks
in a test-like environment that's named something other than "test".

I believe this fixes #768.
  • Loading branch information
cgunther committed Aug 28, 2020
1 parent ab0f8eb commit 74b8f08
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/parallel_tests/tasks.rb
Expand Up @@ -5,7 +5,7 @@ module ParallelTests
module Tasks
class << self
def rails_env
ENV['RAILS_ENV'] || 'test'
'test'
end

def rake_bin
Expand Down
6 changes: 3 additions & 3 deletions spec/parallel_tests/tasks_spec.rb
Expand Up @@ -35,13 +35,13 @@
end

describe ".rails_env" do
it "should be test when nothing was set" do
it "should be test" do
expect(ParallelTests::Tasks.rails_env).to eq("test")
end

it "should be whatever was set" do
it "should disregard whatever was set" do
ENV["RAILS_ENV"] = "foo"
expect(ParallelTests::Tasks.rails_env).to eq("foo")
expect(ParallelTests::Tasks.rails_env).to eq("test")
end
end

Expand Down

0 comments on commit 74b8f08

Please sign in to comment.