diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-21 15:31:15 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-21 15:31:15 -0800 |
commit | bc8d2f6a628dedeb091e4262a3a1b59d0749b1a6 (patch) | |
tree | 52d61165fac5f1c410b9918afa30289180833c48 | |
parent | 625699aa6c1122a0158f421e43aa8b1033586035 (diff) | |
parent | 6b692ee37c08f1abee8c9b8a12f9b7f1234afb00 (diff) | |
download | rails-bc8d2f6a628dedeb091e4262a3a1b59d0749b1a6.tar.gz rails-bc8d2f6a628dedeb091e4262a3a1b59d0749b1a6.tar.bz2 rails-bc8d2f6a628dedeb091e4262a3a1b59d0749b1a6.zip |
Merge pull request #8574 from alindeman/rails_env
Correctly shows RAILS_ENV=development even when ENV['RAILS_ENV'] is not set (e.g., in Pow)
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 2 | ||||
-rw-r--r-- | railties/CHANGELOG.md | 2 | ||||
-rw-r--r-- | railties/lib/rails.rb | 5 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 12 |
4 files changed, 14 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 806b367c6b..273af32237 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -32,7 +32,7 @@ module ActiveRecord class PendingMigrationError < ActiveRecordError#:nodoc: def initialize - super("Migrations are pending; run 'rake db:migrate RAILS_ENV=#{ENV['RAILS_ENV']}' to resolve this issue.") + super("Migrations are pending; run 'rake db:migrate RAILS_ENV=#{Rails.env}' to resolve this issue.") end end diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 961d3dc450..e60c26d132 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -41,8 +41,6 @@ *Yves Senn* -* Ensure that `RAILS_ENV` is set when accessing Rails.env *Steve Klabnik* - * Add `.rake` to list of file extensions included by `rake notes` and `rake notes:custom`. *Brent J. Nordquist* * New test locations `test/models`, `test/helpers`, `test/controllers`, and diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 2797205334..ac8e84e366 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -72,10 +72,7 @@ module Rails end def env - @_env ||= begin - ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" - ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"]) - end + @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development") end def env=(environment) diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index ae1127b509..53109cb041 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1,5 +1,6 @@ require "isolation/abstract_unit" require 'rack/test' +require 'env_helpers' class ::MyMailInterceptor def self.delivering_email(email); email; end @@ -17,6 +18,7 @@ module ApplicationTests class ConfigurationTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation include Rack::Test::Methods + include EnvHelpers def new_app File.expand_path("#{app_path}/../new_app") @@ -41,6 +43,16 @@ module ApplicationTests FileUtils.rm_rf(new_app) if File.directory?(new_app) end + test "Rails.env does not set the RAILS_ENV environment variable which would leak out into rake tasks" do + require "rails" + + switch_env "RAILS_ENV", nil do + Rails.env = "development" + assert_equal "development", Rails.env + assert_nil ENV['RAILS_ENV'] + end + end + test "a renders exception on pending migration" do add_to_config <<-RUBY config.active_record.migration_error = :page_load |