Skip to content

Commit

Permalink
Deprecate support of older config.ru
Browse files Browse the repository at this point in the history
Since Rails 4.0, `config.ru` generated by default uses instances of
`Rails.application`.  Therefore, I think that it is good to deprecate
the old behavior.

Related: rails#9669
  • Loading branch information
y-yagi committed Aug 7, 2017
1 parent 6b0d598 commit f217364
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions railties/CHANGELOG.md
@@ -1,3 +1,7 @@
* Deprecate support of use `Rails::Application` subclass to start Rails server.

*Yuji Yaginuma*

* Add `ruby x.x.x` version to `Gemfile` and create `.ruby-version`
root file containing current Ruby version when new Rails applications are
created.
Expand Down
9 changes: 8 additions & 1 deletion railties/lib/rails/commands/server/server_command.rb
Expand Up @@ -2,6 +2,8 @@
require "optparse"
require "action_dispatch"
require "rails"
require "active_support/deprecation"
require "active_support/core_ext/string/filters"
require_relative "../../dev_caching"

module Rails
Expand All @@ -18,10 +20,15 @@ def initialize(options = nil)
set_environment
end

# TODO: this is no longer required but we keep it for the moment to support older config.ru files.
def app
@app ||= begin
app = super
if app.is_a?(Class)
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Use `Rails::Application` subclass to start the server is deprecated and will be removed in Rails 6.0.
Please change `run #{app}` to `run Rails.application` in config.ru.
MSG
end
app.respond_to?(:to_app) ? app.to_app : app
end
end
Expand Down
31 changes: 31 additions & 0 deletions railties/test/application/server_test.rb
@@ -0,0 +1,31 @@
require "isolation/abstract_unit"
require "rails/command"
require "rails/commands/server/server_command"

module ApplicationTests
class ServerTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation

def setup
build_app
end

def teardown
teardown_app
end

test "deprecate support of older `config.ru`" do
remove_file "config.ru"
app_file "config.ru", <<-RUBY
require_relative 'config/environment'
run AppTemplate::Application
RUBY

server = Rails::Server.new(config: "#{app_path}/config.ru")
server.app

log = File.read(Rails.application.config.paths["log"].first)
assert_match(/DEPRECATION WARNING: Use `Rails::Application` subclass to start the server is deprecated/, log)
end
end
end

0 comments on commit f217364

Please sign in to comment.