Skip to content
Browse files

Correctly shows RAILS_ENV=development even when ENV['RAILS_ENV'] is n…

…ot set (e.g., in Pow)

* Fixes #8025
  • Loading branch information...
1 parent 33b3fa6 commit 6b692ee37c08f1abee8c9b8a12f9b7f1234afb00 @alindeman alindeman committed
Showing with 13 additions and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/migration.rb
  2. +12 −0 railties/test/application/configuration_test.rb
View
2 activerecord/lib/active_record/migration.rb
@@ -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
12 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 @@ 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 6b692ee

Please sign in to comment.
Something went wrong with that request. Please try again.