mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add ENV['RACK_ENV'] support to rake runner/console/server.
This commit is contained in:
parent
396c0681ac
commit
a7695579a5
7 changed files with 67 additions and 5 deletions
|
@ -1,5 +1,9 @@
|
||||||
## Rails 4.0.0 (unreleased) ##
|
## 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*
|
* 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.
|
* Engines with a dummy app include the rake tasks of dependencies in the app namespace.
|
||||||
|
|
|
@ -45,7 +45,7 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
def environment
|
def environment
|
||||||
options[:environment] ||= ENV['RAILS_ENV'] || 'development'
|
options[:environment] ||= ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
||||||
end
|
end
|
||||||
|
|
||||||
def environment?
|
def environment?
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
require 'rbconfig'
|
require 'rbconfig'
|
||||||
|
|
||||||
options = { environment: (ENV['RAILS_ENV'] || "development").dup }
|
options = { environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup }
|
||||||
code_or_file = nil
|
code_or_file = nil
|
||||||
|
|
||||||
if ARGV.first.nil?
|
if ARGV.first.nil?
|
||||||
|
|
|
@ -108,7 +108,7 @@ module Rails
|
||||||
super.merge({
|
super.merge({
|
||||||
Port: 3000,
|
Port: 3000,
|
||||||
DoNotReverseLookup: true,
|
DoNotReverseLookup: true,
|
||||||
environment: (ENV['RAILS_ENV'] || "development").dup,
|
environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup,
|
||||||
daemonize: false,
|
daemonize: false,
|
||||||
debugger: false,
|
debugger: false,
|
||||||
pid: File.expand_path("tmp/pids/server.pid"),
|
pid: File.expand_path("tmp/pids/server.pid"),
|
||||||
|
|
|
@ -67,5 +67,28 @@ module ApplicationTests
|
||||||
|
|
||||||
assert_match "true", Dir.chdir(app_path) { `bundle exec rails runner "puts Rails.application.config.ran"` }
|
assert_match "true", Dir.chdir(app_path) { `bundle exec rails runner "puts Rails.application.config.ran"` }
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -78,6 +78,13 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
|
||||||
assert_match(/\sspecial-production\s/, output)
|
assert_match(/\sspecial-production\s/, output)
|
||||||
end
|
end
|
||||||
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
|
def test_e_option
|
||||||
start ['-e', 'special-production']
|
start ['-e', 'special-production']
|
||||||
|
@ -128,10 +135,18 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_rails_env(env)
|
def with_rails_env(env)
|
||||||
original_rails_env = ENV['RAILS_ENV']
|
rails = ENV['RAILS_ENV']
|
||||||
ENV['RAILS_ENV'] = env
|
ENV['RAILS_ENV'] = env
|
||||||
yield
|
yield
|
||||||
ensure
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,4 +23,24 @@ class Rails::ServerTest < ActiveSupport::TestCase
|
||||||
assert_nil options[:environment]
|
assert_nil options[:environment]
|
||||||
assert_equal 'thin', options[:server]
|
assert_equal 'thin', options[:server]
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue