Use `Rails.env` instead of `ENV['RAILS_ENV']` #7951

Merged
merged 1 commit into from Oct 20, 2012

Conversation

Projects
None yet
4 participants
Contributor

Grandrath commented Oct 15, 2012

ENV['RAILS_ENV'] is not defined unless explicitly specified on the
command line when running rake db:structure:load. This patch lets
the rake task retrieve the environment from Rails.env which defaults
to "development".

I think the idea is to default to test in case RAILS_ENV is not set. This way we'd be defaulting to development, which changes the functionality, making the || 'test' clause "useless". I don't think we're supposed to change that, though.

Owner

rafaelfranca commented Oct 15, 2012

Agree with @carlosantoniodasilva. Thank you for the pull request.

Contributor

Grandrath commented Oct 15, 2012

Are you sure this behavior is desired? rake db:schema:load loads the db schema into the development database without the need to specify RAILS_ENV=development on the command line. rake db:structure:load is supposed to behave alike.

Furthermore rake db:structure:load did access the development database in version 3.2.6. That changed somewhere on the road between 3.2.6 and 3.2.8. Can you confirm that this change in behavior is by design?

@rafaelfranca rafaelfranca reopened this Oct 15, 2012

Owner

rafaelfranca commented Oct 15, 2012

@Grandrath you are right. So the best thing to do is remove the arguments of current_config and it will use the Rails.env

Contributor

Grandrath commented Oct 15, 2012

OK, I updated the pull request accordingly.

Owner

rafaelfranca commented Oct 15, 2012

@Grandrath great! We don't have tests for this code, so could I ask to you test it in a blank application?

Also these are the changes between Rails 3.2.8 and 3.2.6 v3.2.6...v3.2.8diff-61

@Grandrath this is new info to the pull request :). So yeah, if something has changed and the code is now not behaving as it was before, I agree with you, thanks for spotting this!

I am wondering what happening in this issue?

I was going to file a bug report for the fact that 'rake' or 'rake default' with rspec-rails is no longer setting the rails environment into 'test'.

I'm a 0.5.0 rails user - and as near as i can rememeber - i could always rely on 'rake' running the test harness in the RAILS_ENV test environment.

Is this intentionally changing?

Thank you so much for your hard work on this great open source product!

versions

rspec-rails (2.11.0)

rails (3.2.7)
actionmailer (= 3.2.7)
actionpack (= 3.2.7)
activerecord (= 3.2.7)
activeresource (= 3.2.7)
activesupport (= 3.2.7)
bundler (~> 1.0)
railties (= 3.2.7)

Owner

rafaelfranca commented Oct 15, 2012

@robotarmy please use the Rails 3.2.8 version. The 3.2.7 has this bug.

Thank you so much!

:D

On Mon, Oct 15, 2012 at 4:03 PM, Rafael Mendonça França <
notifications@github.com> wrote:

@robotarmy https://github.com/robotarmy please use the Rails 3.2.8
version. The 3.2.7 has this bug.


Reply to this email directly or view it on GitHubhttps://github.com/rails/rails/pull/7951#issuecomment-9465348.


Modern Yoga vs Traditional Yoga
http://swamij.com/traditional-yoga.htm#swamirama

Contributor

Grandrath commented Oct 16, 2012

@rafaelfranca OK, I'll test the change in a blank app. But I guess I don't find the time to look into this today.

@Grandrath also make sure to squash your commits, thanks!

@rafaelfranca 3.2.8 worked 💃

Owner

rafaelfranca commented Oct 18, 2012

@robotarmy thank you to share it back

Owner

rafaelfranca commented Oct 18, 2012

@Grandrath just ping us if everything works fine and we will merge.

Grandrath added a commit to Grandrath/rails that referenced this pull request Oct 18, 2012

Use `Rails.env` instead of `ENV['RAILS_ENV']`; #7951
`ENV['RAILS_ENV']` is not defined unless explicitly specified on the
command line when running `rake db:structure:load`. This patch lets
the rake task retrieve the environment from `Rails.env` which defaults
to "development".
Don't use test environment by default when running rake db:structure:…
…load; #7951

`ENV['RAILS_ENV']` is not defined unless explicitly specified on the
command line when running `rake db:structure:load`.
Contributor

Grandrath commented Oct 18, 2012

I added rails/rails#7986 which solves this issue for 3.2.8 (tested).

As for this pull request: I have trouble testing this in a blank app from master. When I try to run rake db:structure:load I get the error message

rake aborted!
undefined method `whitelist_attributes=' for ActiveRecord::Base:Class

Can someone with more experience in Rails development help me, please?

@Grandrath you shouldn't have this option anymore when generating a Rails 4 application, do you have a stack trace?

Contributor

Grandrath commented Oct 18, 2012

@carlosantoniodasilva Thanks. It works now after running rake rails:update.

I can now confirm that this patch does what it should. Thank you all for your fast and kind responses!

carlosantoniodasilva added a commit that referenced this pull request Oct 20, 2012

Merge pull request #7951 from Grandrath/patch-1
Use `Rails.env` instead of `ENV['RAILS_ENV']`.
Fix behavior of `rake db:structure:load`.

@carlosantoniodasilva carlosantoniodasilva merged commit c869ce0 into rails:master Oct 20, 2012

@Grandrath great, thanks for verifying everything.

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