diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-05 09:19:32 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-05 09:19:32 -0800 |
commit | ddd4fac8cc1dc3cbffdd4ef71fd260b601a17695 (patch) | |
tree | 07955176072c0881e71dfc782fbb3d730560a262 /railties | |
parent | 396c0681acab95a58f0583d722f488b5b01398d8 (diff) | |
parent | a7695579a5979245f7d5e683a67bbfc096f3099a (diff) | |
download | rails-ddd4fac8cc1dc3cbffdd4ef71fd260b601a17695.tar.gz rails-ddd4fac8cc1dc3cbffdd4ef71fd260b601a17695.tar.bz2 rails-ddd4fac8cc1dc3cbffdd4ef71fd260b601a17695.zip |
Merge pull request #8427 from kennyj/support_rack_env
Add ENV['RACK_ENV'] support to rake runner/console/server.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 4 | ||||
-rw-r--r-- | railties/lib/rails/commands/console.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/commands/runner.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/commands/server.rb | 2 | ||||
-rw-r--r-- | railties/test/application/runner_test.rb | 23 | ||||
-rw-r--r-- | railties/test/commands/console_test.rb | 19 | ||||
-rw-r--r-- | railties/test/commands/server_test.rb | 20 |
7 files changed, 67 insertions, 5 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index c3da3094dc..01dd86c23e 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 4.0.0 (unreleased) ## +* Add ENV['RACK_ENV'] support to `rails runner/console/server`. + + *kennyj* + * Add `db` to list of folders included by `rake notes` and `rake notes:custom`. *Antonio Cangiano* * Engines with a dummy app include the rake tasks of dependencies in the app namespace. diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index 92cee6b638..aef7600fbd 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -45,7 +45,7 @@ module Rails end def environment - options[:environment] ||= ENV['RAILS_ENV'] || 'development' + options[:environment] ||= ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' end def environment? diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index 62d82cc005..6adbdc6e0b 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -1,7 +1,7 @@ require 'optparse' require 'rbconfig' -options = { environment: (ENV['RAILS_ENV'] || "development").dup } +options = { environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup } code_or_file = nil if ARGV.first.nil? diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 0b897d736d..cdb29a8156 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -108,7 +108,7 @@ module Rails super.merge({ Port: 3000, DoNotReverseLookup: true, - environment: (ENV['RAILS_ENV'] || "development").dup, + environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup, daemonize: false, debugger: false, pid: File.expand_path("tmp/pids/server.pid"), diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb index 81ed5873a5..797c7a9470 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -67,5 +67,28 @@ module ApplicationTests assert_match "true", Dir.chdir(app_path) { `bundle exec rails runner "puts Rails.application.config.ran"` } end + + def test_default_environment + assert_match "development", Dir.chdir(app_path) { `bundle exec rails runner "puts Rails.env"` } + end + + def test_environment_with_rails_env + orig = ENV['RAILS_ENV'] + ENV['RAILS_ENV'] = "production" + assert_match "production", Dir.chdir(app_path) { `bundle exec rails runner "puts Rails.env"` } + ensure + ENV['RAILS_ENV'] = orig + end + + def test_environment_with_rails_env + rack, rails = ENV['RACK_ENV'], ENV['RAILS_ENV'] + ENV['RACK_ENV'] = "production" + ENV['RAILS_ENV'] = nil + assert_match "production", Dir.chdir(app_path) { `bundle exec rails runner "puts Rails.env"` } + ensure + ENV['RAILS_ENV'] = rails + ENV['RACK_ENV'] = rack + end + end end diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb index f99ea13022..4062905c16 100644 --- a/railties/test/commands/console_test.rb +++ b/railties/test/commands/console_test.rb @@ -78,6 +78,13 @@ class Rails::ConsoleTest < ActiveSupport::TestCase assert_match(/\sspecial-production\s/, output) end end + + def test_default_environment_with_rack_env + with_rack_env 'production' do + start + assert_match(/\sproduction\s/, output) + end + end def test_e_option start ['-e', 'special-production'] @@ -128,10 +135,18 @@ class Rails::ConsoleTest < ActiveSupport::TestCase end def with_rails_env(env) - original_rails_env = ENV['RAILS_ENV'] + rails = ENV['RAILS_ENV'] ENV['RAILS_ENV'] = env yield ensure - ENV['RAILS_ENV'] = original_rails_env + ENV['RAILS_ENV'] = rails + end + + def with_rack_env(env) + rack = ENV['RACK_ENV'] + ENV['RACK_ENV'] = env + with_rails_env(nil) { yield } + ensure + ENV['RACK_ENV'] = rack end end diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb index 4a3ea82e3d..6a75207ebb 100644 --- a/railties/test/commands/server_test.rb +++ b/railties/test/commands/server_test.rb @@ -23,4 +23,24 @@ class Rails::ServerTest < ActiveSupport::TestCase assert_nil options[:environment] assert_equal 'thin', options[:server] end + + def test_environment_with_rails_env + rails = ENV['RAILS_ENV'] + ENV['RAILS_ENV'] = 'production' + server = Rails::Server.new + assert_equal 'production', server.options[:environment] + ensure + ENV['RAILS_ENV'] = rails + end + + def test_environment_with_rack_env + rack, rails = ENV['RACK_ENV'], ENV['RAILS_ENV'] + ENV['RAILS_ENV'] = nil + ENV['RACK_ENV'] = 'production' + server = Rails::Server.new + assert_equal 'production', server.options[:environment] + ensure + ENV['RACK_ENV'] = rack + ENV['RAILS_ENV'] = rails + end end |