diff options
26 files changed, 49 insertions, 141 deletions
@@ -60,7 +60,6 @@ instance_eval File.read local_gemfile if File.exist? local_gemfile group :test do # FIX: Our test suite isn't ready to run in random order yet gem 'minitest', '< 5.3.4' - gem 'method_source' platforms :mri_19 do gem 'ruby-prof', '~> 0.11.2' diff --git a/Gemfile.lock b/Gemfile.lock index 1139e05aa5..cd360958d3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,6 +87,7 @@ PATH railties (5.0.0.alpha) actionpack (= 5.0.0.alpha) activesupport (= 5.0.0.alpha) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) @@ -261,7 +262,6 @@ DEPENDENCIES json kindlerb (= 0.1.1) mail! - method_source minitest (< 5.3.4) mocha (~> 0.14) mysql (>= 2.9.0) diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 62ff1be5c9..a67579d94f 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -36,7 +36,7 @@ require 'pp' # require 'pp' early to prevent hidden_methods from not picking up module Rails class << self def env - @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "test") + @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || "test") end end end diff --git a/actionview/test/abstract_unit.rb b/actionview/test/abstract_unit.rb index 4635c645d0..382bd72f20 100644 --- a/actionview/test/abstract_unit.rb +++ b/actionview/test/abstract_unit.rb @@ -28,7 +28,7 @@ require 'pp' # require 'pp' early to prevent hidden_methods from not picking up module Rails class << self def env - @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "test") + @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || "test") end end end diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 64985ee933..09579884df 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -57,7 +57,7 @@ module ActiveRecord # * <tt>:database</tt> - The name of the database. No default, must be provided. # * <tt>:encoding</tt> - (Optional) Sets the client encoding by executing "SET NAMES <encoding>" after connection. # * <tt>:reconnect</tt> - Defaults to false (See MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html). - # * <tt>:strict</tt> - Defaults to true. Enable STRICT_ALL_TABLES. (See MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html) + # * <tt>:strict</tt> - Defaults to true. Enable STRICT_ALL_TABLES. (See MySQL documentation: http://dev.mysql.com/doc/refman/5.6/en/sql-mode.html) # * <tt>:variables</tt> - (Optional) A hash session variables to send as <tt>SET @@SESSION.key = value</tt> on each database connection. Use the value +:default+ to set a variable to its DEFAULT value. (See MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/set-statement.html). # * <tt>:sslca</tt> - Necessary to use MySQL with an SSL connection. # * <tt>:sslkey</tt> - Necessary to use MySQL with an SSL connection. diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb index 24f5849e45..d0deb7751c 100644 --- a/activerecord/lib/active_record/connection_handling.rb +++ b/activerecord/lib/active_record/connection_handling.rb @@ -1,6 +1,6 @@ module ActiveRecord module ConnectionHandling - RAILS_ENV = -> { (Rails.env if defined?(Rails.env)) || ENV["RAILS_ENV"] || ENV["RACK_ENV"] } + RAILS_ENV = -> { (Rails.env if defined?(Rails.env)) || ENV["RAILS_ENV"] } DEFAULT_ENV = -> { RAILS_ENV.call || "default_env" } # Establishes the connection to the database. Accepts a hash as input where diff --git a/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb b/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb index 9ee92a3cd2..9756a2b891 100644 --- a/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +++ b/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb @@ -5,13 +5,11 @@ module ActiveRecord class MergeAndResolveDefaultUrlConfigTest < ActiveRecord::TestCase def setup @previous_database_url = ENV.delete("DATABASE_URL") - @previous_rack_env = ENV.delete("RACK_ENV") @previous_rails_env = ENV.delete("RAILS_ENV") end teardown do ENV["DATABASE_URL"] = @previous_database_url - ENV["RACK_ENV"] = @previous_rack_env ENV["RAILS_ENV"] = @previous_rails_env end @@ -41,16 +39,6 @@ module ActiveRecord assert_equal expected, actual end - def test_resolver_with_database_uri_and_current_env_symbol_key_and_rack_env - ENV['DATABASE_URL'] = "postgres://localhost/foo" - ENV['RACK_ENV'] = "foo" - - config = { "not_production" => { "adapter" => "not_postgres", "database" => "not_foo" } } - actual = resolve_spec(:foo, config) - expected = { "adapter" => "postgresql", "database" => "foo", "host" => "localhost" } - assert_equal expected, actual - end - def test_resolver_with_database_uri_and_known_key ENV['DATABASE_URL'] = "postgres://localhost/foo" config = { "production" => { "adapter" => "not_postgres", "database" => "not_foo", "host" => "localhost" } } @@ -173,28 +161,6 @@ module ActiveRecord assert_equal nil, actual[:test] end - def test_blank_with_database_url_with_rack_env - ENV['RACK_ENV'] = "not_production" - ENV['DATABASE_URL'] = "postgres://localhost/foo" - - config = {} - actual = resolve_config(config) - expected = { "adapter" => "postgresql", - "database" => "foo", - "host" => "localhost" } - - assert_equal expected, actual["not_production"] - assert_equal nil, actual["production"] - assert_equal nil, actual["default_env"] - assert_equal nil, actual["development"] - assert_equal nil, actual["test"] - assert_equal nil, actual[:default_env] - assert_equal nil, actual[:not_production] - assert_equal nil, actual[:production] - assert_equal nil, actual[:development] - assert_equal nil, actual[:test] - end - def test_database_url_with_ipv6_host_and_port ENV['DATABASE_URL'] = "postgres://[::1]:5454/foo" diff --git a/guides/source/initialization.md b/guides/source/initialization.md index 8fbb234698..43f15d1551 100644 --- a/guides/source/initialization.md +++ b/guides/source/initialization.md @@ -278,7 +278,7 @@ def parse_options(args) options.merge! opt_parser.parse!(args) options[:config] = ::File.expand_path(options[:config]) - ENV["RACK_ENV"] = options[:environment] + ENV["RAILS_ENV"] = options[:environment] options end ``` @@ -287,7 +287,7 @@ With the `default_options` set to this: ```ruby def default_options - environment = ENV['RACK_ENV'] || 'development' + environment = ENV['RAILS_ENV'] || 'development' default_host = environment == 'development' ? 'localhost' : '0.0.0.0' { @@ -669,7 +669,7 @@ def self.run(app, options = {}) end if options[:environment] - ENV['RACK_ENV'] = options[:environment].to_s + ENV['RAILS_ENV'] = options[:environment].to_s end server = ::Puma::Server.new(app) @@ -677,7 +677,7 @@ def self.run(app, options = {}) puts "Puma #{::Puma::Const::PUMA_VERSION} starting..." puts "* Min threads: #{min}, max threads: #{max}" - puts "* Environment: #{ENV['RACK_ENV']}" + puts "* Environment: #{ENV['RAILS_ENV']}" puts "* Listening on tcp://#{options[:Host]}:#{options[:Port]}" server.add_tcp_listener options[:Host], options[:Port] diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index f4a8cf86b6..f1fa3c4bf2 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,10 @@ +* 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 b1f7c29b5a..5d46bbefe6 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"] || ENV["RACK_ENV"] || "development") + @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || "development") end # Sets the Rails environment. diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index 5d37a2b699..48b1ad884b 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'] || ENV['RACK_ENV'] || 'development' + options[:environment] ||= ENV['RAILS_ENV'] || 'development' end def environment? diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index 5175e31f14..be0c0fc659 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"] || ENV["RACK_ENV"] || "development" + ENV["RAILS_ENV"] || "development" end end diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index 86bce9b2fe..66a9ebf38c 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'] || ENV['RACK_ENV'] || "development").dup } +options = { environment: (ENV['RAILS_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 546d3725d8..397a9cf406 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'] || ENV['RACK_ENV'] || "development").dup, + environment: (ENV['RAILS_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/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 82a0315379..c11bb58bfa 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -36,10 +36,6 @@ group :development, :test do # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' <% end -%> - - # Adds `Method#source` and `Method#comment` to get the source code of a - # method from the console - gem 'method_source' <% end -%> end <% if RUBY_PLATFORM.match(/bccwin|cygwin|emx|mingw|mswin|wince|java/) -%> diff --git a/railties/lib/rails/test_unit/runner.rb b/railties/lib/rails/test_unit/runner.rb index aec4707947..6700d90a33 100644 --- a/railties/lib/rails/test_unit/runner.rb +++ b/railties/lib/rails/test_unit/runner.rb @@ -129,7 +129,7 @@ module Rails location = method.source_location start_line = location.last end_line = method.source.split("\n").size + start_line - 1 - methods_map << [location.first, test_method, start_line, end_line] + methods_map << [File.expand_path(location.first), test_method, start_line, end_line] end end methods_map diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index f3a43a12db..0f26621b59 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -5,8 +5,8 @@ task default: :test desc "Runs all tests in test folder" task :test do $: << "test" - ARGV.shift if ARGV[0] == "test" - Rails::TestRunner.run(ARGV) + args = ARGV[0] == "test" ? ARGV[1..-1] : [] + Rails::TestRunner.run(args) end namespace :test do diff --git a/railties/railties.gemspec b/railties/railties.gemspec index 5d79325a7a..001882fdc6 100644 --- a/railties/railties.gemspec +++ b/railties/railties.gemspec @@ -28,6 +28,7 @@ Gem::Specification.new do |s| s.add_dependency 'rake', '>= 0.8.7' s.add_dependency 'thor', '>= 0.18.1', '< 2.0' + s.add_dependency 'method_source' s.add_development_dependency 'actionview', version end diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index c414732f92..1da108f1e1 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -203,9 +203,7 @@ 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 @@ -225,7 +223,6 @@ 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 6595c40f8b..b59202e68e 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -79,11 +79,5 @@ 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 de0cf0ba9e..d7614de9e3 100644 --- a/railties/test/commands/console_test.rb +++ b/railties/test/commands/console_test.rb @@ -70,13 +70,6 @@ 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 a3cd1eb0ed..b8c7354ed0 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -82,20 +82,15 @@ 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 ba688f1e9e..8427ac1bc2 100644 --- a/railties/test/commands/server_test.rb +++ b/railties/test/commands/server_test.rb @@ -27,61 +27,36 @@ class Rails::ServerTest < ActiveSupport::TestCase end def test_environment_with_rails_env - with_rack_env nil do - with_rails_env 'production' do - server = Rails::Server.new - assert_equal 'production', server.options[:environment] - end + with_rails_env 'production' do + server = Rails::Server.new + assert_equal 'production', server.options[:environment] end end - def test_environment_with_rack_env + def test_log_stdout with_rails_env nil do - with_rack_env 'production' do - server = Rails::Server.new - assert_equal 'production', server.options[:environment] - end - end - end + args = [] + options = Rails::Server::Options.new.parse!(args) + assert_equal true, options[:log_stdout] - 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] + args = ["-e", "development"] + options = Rails::Server::Options.new.parse!(args) + assert_equal true, options[:log_stdout] - args = ["-e", "development"] + args = ["-e", "production"] + options = Rails::Server::Options.new.parse!(args) + assert_equal false, options[:log_stdout] + + with_rails_env 'development' do + args = [] options = Rails::Server::Options.new.parse!(args) assert_equal true, options[:log_stdout] + end - args = ["-e", "production"] + with_rails_env 'production' do + args = [] 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 330fe150ca..fea06e528f 100644 --- a/railties/test/env_helpers.rb +++ b/railties/test/env_helpers.rb @@ -12,15 +12,6 @@ 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 diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 4c5dd70a88..00a7932267 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -443,13 +443,6 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_inclusion_of_method_source - run_generator - assert_file "Gemfile" do |content| - assert_gem 'method_source' - end - end - def test_template_from_dir_pwd FileUtils.cd(Rails.root) assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"])) diff --git a/railties/test/test_unit/runner_test.rb b/railties/test/test_unit/runner_test.rb index c040c71635..9ea8b2c114 100644 --- a/railties/test/test_unit/runner_test.rb +++ b/railties/test/test_unit/runner_test.rb @@ -41,7 +41,7 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase test "parse the filename and line" do file = "test/test_unit/runner_test.rb" - absolute_file = __FILE__ + absolute_file = File.expand_path __FILE__ options = @options.parse(["#{file}:20"]) assert_equal absolute_file, options[:filename] assert_equal 20, options[:line] @@ -90,21 +90,22 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase test "run multiple files and run one file by line" do line = __LINE__ + absolute_file = File.expand_path(__FILE__) options = @options.parse([__dir__, "#{__FILE__}:#{line}"]) assert_equal ["#{__dir__}/**/*_test.rb"], options[:patterns] - assert_equal __FILE__, options[:filename] + assert_equal absolute_file, options[:filename] assert_equal line, options[:line] runner = Rails::TestRunner.new(options) - assert_equal [__FILE__], runner.test_files, 'Only returns the file that running by line' + assert_equal [absolute_file], runner.test_files, 'Only returns the file that running by line' end test "running multiple files passing line number" do line = __LINE__ options = @options.parse(["foobar.rb:8", "#{__FILE__}:#{line}"]) - assert_equal __FILE__, options[:filename], 'Returns the last file' + assert_equal File.expand_path(__FILE__), options[:filename], 'Returns the last file' assert_equal line, options[:line] end end |