rails new application - defaults to test environment #13241

Closed
DHB opened this Issue Dec 9, 2013 · 2 comments

Comments

Projects
None yet
3 participants

DHB commented Dec 9, 2013

Some of my rake tasks check for ENV['RAILS_ENV'] respectively `Rails.env.development?`` to do other stuff.

Even a fresh rails app
rails new application
should default (IMHO) to development mode.

Instead it defaults to test?

This is on:

ruby -v && rails -v && rake --version && gem --version && bundle --version                                                                                                                             
ruby 2.0.0p247 (2013-06-27) [i386-mingw32]                                                                                                                                                             
Rails 4.0.2                                                                                                                                                                                            
rake, version 10.1.0                                                                                                                                                                                   
2.0.3                                                                                                                                                                                                  
Bundler version 1.3.5 

Confusing enough irb and rails c both show the right and anticipated environment:

$ rails c
Loading development environment (Rails 4.0.2)
irb(main):001:0> Rails.env.development?
=> true
irb(main):002:0> exit

To reproduce just place

puts "This is the Rails ENV variable: #{Rails.env.upcase}"

into e.g. envi.rake in .lib\tasks and do a simple

rake -T

On the contrary

rails new application -T

works as expected since the test-unit\railtie framework does not get loaded via application.rb.

This is absolutely low priority and no big deal. I am not using the unit tests anyway and I usually generate my apps without require rails/all.

Really not sure whether I am missing something and this is correct 'behaviour' - if so, I apologize ...

DHB commented Dec 9, 2013

To me it looks like the check in railties-4.0.2/lib/rails/test-unit/railtie.rb when calling the Rake.application.top_level_tasks method returns true when it finds a test task in the task list and hence sets Rails.env to 'test'.
Shouldn't this be set only when a test task is INVOKED ?

Related to #12778 /cc @tenderlove

@rafaelfranca rafaelfranca modified the milestones: 4.0.5, 4.0.4, 4.0.6 Mar 10, 2014

rafaelfranca added a commit that referenced this issue Mar 28, 2014

Merge pull request #12778 from etehtsea/rake-default-fix
Don't load test env by default.

Closes #13241

rafaelfranca added a commit that referenced this issue Mar 28, 2014

Merge pull request #12778 from etehtsea/rake-default-fix
Don't load test env by default.

Closes #13241

Conflicts:
	railties/CHANGELOG.md

@rafaelfranca rafaelfranca modified the milestones: 4.0.6, 4.0.7 May 21, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment