Permalink
Browse files

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)
  • Loading branch information...
rafaelfranca committed Dec 21, 2012
2 parents 625699a + 6b692ee commit bc8d2f6a628dedeb091e4262a3a1b59d0749b1a6
@@ -32,7 +32,7 @@ def initialize(name)
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
View
@@ -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
View
@@ -72,10 +72,7 @@ def root
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)
@@ -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 @@ def teardown
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

0 comments on commit bc8d2f6

Please sign in to comment.