aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md7
-rw-r--r--railties/lib/rails.rb2
-rw-r--r--railties/lib/rails/application.rb17
-rw-r--r--railties/lib/rails/commands/console.rb2
-rw-r--r--railties/lib/rails/commands/dbconsole.rb2
-rw-r--r--railties/lib/rails/commands/runner.rb2
-rw-r--r--railties/lib/rails/commands/server.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml2
-rw-r--r--railties/test/application/build_original_fullpath_test.rb27
-rw-r--r--railties/test/application/rake/dbs_test.rb3
-rw-r--r--railties/test/application/runner_test.rb6
-rw-r--r--railties/test/commands/console_test.rb7
-rw-r--r--railties/test/commands/dbconsole_test.rb5
-rw-r--r--railties/test/commands/server_test.rb63
-rw-r--r--railties/test/env_helpers.rb9
16 files changed, 84 insertions, 74 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index f1fa3c4bf2..f4a8cf86b6 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,10 +1,3 @@
-* Don't fallback to using `RACK_ENV` when `RAILS_ENV` is not present.
-
- RACK_ENV does not have the same meaning as RAILS_ENV, and cannot be used as a fallback.
- See http://www.hezmatt.org/~mpalmer/blog/2013/10/13/rack_env-its-not-for-you.html
-
- *Damien Mathieu*
-
* Add a new-line to the end of route method generated code.
We need to add a `\n`, because we cannot have two routes
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb
index 5d46bbefe6..b1f7c29b5a 100644
--- a/railties/lib/rails.rb
+++ b/railties/lib/rails.rb
@@ -62,7 +62,7 @@ module Rails
# Rails.env.development? # => true
# Rails.env.production? # => false
def env
- @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || "development")
+ @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
end
# Sets the Rails environment.
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index ff6c905f3e..e9683d4a95 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -159,8 +159,9 @@ module Rails
# Implements call according to the Rack API. It simply
# dispatches the request to the underlying middleware stack.
def call(env)
- env["ORIGINAL_FULLPATH"] = build_original_fullpath(env)
- env["ORIGINAL_SCRIPT_NAME"] = env["SCRIPT_NAME"]
+ req = ActionDispatch::Request.new env
+ env["ORIGINAL_FULLPATH"] = req.fullpath
+ env["ORIGINAL_SCRIPT_NAME"] = req.script_name
super(env)
end
@@ -504,18 +505,6 @@ module Rails
default_stack.build_stack
end
- def build_original_fullpath(env) #:nodoc:
- path_info = env["PATH_INFO"]
- query_string = env["QUERY_STRING"]
- script_name = env["SCRIPT_NAME"]
-
- if query_string.present?
- "#{script_name}#{path_info}?#{query_string}"
- else
- "#{script_name}#{path_info}"
- end
- end
-
def validate_secret_key_config! #:nodoc:
if secrets.secret_key_base.blank?
ActiveSupport::Deprecation.warn "You didn't set `secret_key_base`. " +
diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb
index 48b1ad884b..5d37a2b699 100644
--- a/railties/lib/rails/commands/console.rb
+++ b/railties/lib/rails/commands/console.rb
@@ -57,7 +57,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/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb
index be0c0fc659..5175e31f14 100644
--- a/railties/lib/rails/commands/dbconsole.rb
+++ b/railties/lib/rails/commands/dbconsole.rb
@@ -107,7 +107,7 @@ module Rails
if Rails.respond_to?(:env)
Rails.env
else
- ENV["RAILS_ENV"] || "development"
+ ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
end
end
diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb
index 66a9ebf38c..86bce9b2fe 100644
--- a/railties/lib/rails/commands/runner.rb
+++ b/railties/lib/rails/commands/runner.rb
@@ -1,6 +1,6 @@
require 'optparse'
-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 397a9cf406..546d3725d8 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -95,7 +95,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,
pid: File.expand_path("tmp/pids/server.pid"),
config: File.expand_path("config.ru")
diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml
index acb93939e1..f5b62e8fb3 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml
+++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml
@@ -7,7 +7,7 @@
# gem 'activerecord-jdbcmysql-adapter'
#
# And be sure to use new-style password hashing:
-# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
+# http://dev.mysql.com/doc/refman/5.6/en/old-client.html
#
default: &default
adapter: mysql
diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml
index 596c916573..b0767bd93a 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml
+++ b/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml
@@ -7,7 +7,7 @@
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
-# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
+# http://dev.mysql.com/doc/refman/5.6/en/old-client.html
#
default: &default
adapter: mysql2
diff --git a/railties/test/application/build_original_fullpath_test.rb b/railties/test/application/build_original_fullpath_test.rb
deleted file mode 100644
index 647ffb097a..0000000000
--- a/railties/test/application/build_original_fullpath_test.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-require "abstract_unit"
-
-module ApplicationTests
- class BuildOriginalPathTest < ActiveSupport::TestCase
- def test_include_original_PATH_info_in_ORIGINAL_FULLPATH
- env = { 'PATH_INFO' => '/foo/' }
- assert_equal "/foo/", Rails.application.send(:build_original_fullpath, env)
- end
-
- def test_include_SCRIPT_NAME
- env = {
- 'SCRIPT_NAME' => '/foo',
- 'PATH_INFO' => '/bar'
- }
-
- assert_equal "/foo/bar", Rails.application.send(:build_original_fullpath, env)
- end
-
- def test_include_QUERY_STRING
- env = {
- 'PATH_INFO' => '/foo',
- 'QUERY_STRING' => 'bar',
- }
- assert_equal "/foo?bar", Rails.application.send(:build_original_fullpath, env)
- end
- end
-end
diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb
index 1da108f1e1..c414732f92 100644
--- a/railties/test/application/rake/dbs_test.rb
+++ b/railties/test/application/rake/dbs_test.rb
@@ -203,7 +203,9 @@ module ApplicationTests
test 'db:setup loads schema and seeds database' do
begin
@old_rails_env = ENV["RAILS_ENV"]
+ @old_rack_env = ENV["RACK_ENV"]
ENV.delete "RAILS_ENV"
+ ENV.delete "RACK_ENV"
app_file 'db/schema.rb', <<-RUBY
ActiveRecord::Schema.define(version: "1") do
@@ -223,6 +225,7 @@ module ApplicationTests
end
ensure
ENV["RAILS_ENV"] = @old_rails_env
+ ENV["RACK_ENV"] = @old_rack_env
end
end
end
diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb
index b59202e68e..6595c40f8b 100644
--- a/railties/test/application/runner_test.rb
+++ b/railties/test/application/runner_test.rb
@@ -79,5 +79,11 @@ module ApplicationTests
assert_match "production", Dir.chdir(app_path) { `bundle exec rails runner "puts Rails.env"` }
end
end
+
+ def test_environment_with_rack_env
+ with_rack_env "production" do
+ assert_match "production", Dir.chdir(app_path) { `bundle exec rails runner "puts Rails.env"` }
+ end
+ end
end
end
diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb
index d7614de9e3..de0cf0ba9e 100644
--- a/railties/test/commands/console_test.rb
+++ b/railties/test/commands/console_test.rb
@@ -70,6 +70,13 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
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']
assert_match(/\sspecial-production\s/, output)
diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb
index b8c7354ed0..a3cd1eb0ed 100644
--- a/railties/test/commands/dbconsole_test.rb
+++ b/railties/test/commands/dbconsole_test.rb
@@ -82,15 +82,20 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase
assert_equal "test", Rails::DBConsole.new.environment
ENV['RAILS_ENV'] = nil
+ ENV['RACK_ENV'] = nil
Rails.stub(:respond_to?, false) do
assert_equal "development", Rails::DBConsole.new.environment
+ ENV['RACK_ENV'] = "rack_env"
+ assert_equal "rack_env", Rails::DBConsole.new.environment
+
ENV['RAILS_ENV'] = "rails_env"
assert_equal "rails_env", Rails::DBConsole.new.environment
end
ensure
ENV['RAILS_ENV'] = "test"
+ ENV['RACK_ENV'] = nil
end
def test_rails_env_is_development_when_argument_is_dev
diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb
index 8427ac1bc2..ba688f1e9e 100644
--- a/railties/test/commands/server_test.rb
+++ b/railties/test/commands/server_test.rb
@@ -27,36 +27,61 @@ class Rails::ServerTest < ActiveSupport::TestCase
end
def test_environment_with_rails_env
- with_rails_env 'production' do
- server = Rails::Server.new
- assert_equal 'production', server.options[:environment]
+ with_rack_env nil do
+ with_rails_env 'production' do
+ server = Rails::Server.new
+ assert_equal 'production', server.options[:environment]
+ end
end
end
- def test_log_stdout
+ def test_environment_with_rack_env
with_rails_env nil do
- args = []
- options = Rails::Server::Options.new.parse!(args)
- assert_equal true, options[:log_stdout]
-
- args = ["-e", "development"]
- options = Rails::Server::Options.new.parse!(args)
- assert_equal true, options[:log_stdout]
-
- args = ["-e", "production"]
- options = Rails::Server::Options.new.parse!(args)
- assert_equal false, options[:log_stdout]
+ with_rack_env 'production' do
+ server = Rails::Server.new
+ assert_equal 'production', server.options[:environment]
+ end
+ end
+ end
- with_rails_env 'development' do
+ def test_log_stdout
+ with_rack_env nil do
+ with_rails_env nil do
args = []
options = Rails::Server::Options.new.parse!(args)
assert_equal true, options[:log_stdout]
- end
- with_rails_env 'production' do
- args = []
+ args = ["-e", "development"]
+ options = Rails::Server::Options.new.parse!(args)
+ assert_equal true, options[:log_stdout]
+
+ args = ["-e", "production"]
options = Rails::Server::Options.new.parse!(args)
assert_equal false, options[:log_stdout]
+
+ with_rack_env 'development' do
+ args = []
+ options = Rails::Server::Options.new.parse!(args)
+ assert_equal true, options[:log_stdout]
+ end
+
+ with_rack_env 'production' do
+ args = []
+ options = Rails::Server::Options.new.parse!(args)
+ assert_equal false, options[:log_stdout]
+ end
+
+ with_rails_env 'development' do
+ args = []
+ options = Rails::Server::Options.new.parse!(args)
+ assert_equal true, options[:log_stdout]
+ end
+
+ with_rails_env 'production' do
+ args = []
+ options = Rails::Server::Options.new.parse!(args)
+ assert_equal false, options[:log_stdout]
+ end
end
end
end
diff --git a/railties/test/env_helpers.rb b/railties/test/env_helpers.rb
index fea06e528f..330fe150ca 100644
--- a/railties/test/env_helpers.rb
+++ b/railties/test/env_helpers.rb
@@ -12,6 +12,15 @@ module EnvHelpers
end
end
+ def with_rack_env(env)
+ Rails.instance_variable_set :@_env, nil
+ switch_env 'RACK_ENV', env do
+ switch_env 'RAILS_ENV', nil do
+ yield
+ end
+ end
+ end
+
def switch_env(key, value)
old, ENV[key] = ENV[key], value
yield