Skip to content

Commit f9ed833

Browse files
committed
Remove deprecated CONTROLLER environment variable for routes task
1 parent f778281 commit f9ed833

File tree

3 files changed

+29
-49
lines changed

3 files changed

+29
-49
lines changed

railties/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove deprecated `CONTROLLER` environment variable for `routes` task.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove deprecated tasks: `rails:update`, `rails:template`, `rails:template:copy`,
26
`rails:update:configs` and `rails:update:bin`.
37

railties/lib/rails/tasks/routes.rake

-7
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,8 @@ task routes: :environment do
77
all_routes = Rails.application.routes.routes
88
require "action_dispatch/routing/inspector"
99
inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
10-
if ARGV.any? { |argv| argv.start_with? "CONTROLLER" }
11-
puts <<-eow.strip_heredoc
12-
Passing `CONTROLLER` to `bin/rails routes` is deprecated and will be removed in Rails 5.1.
13-
Please use `bin/rails routes -c controller_name` instead.
14-
eow
15-
end
1610

1711
routes_filter = nil
18-
routes_filter = { controller: ENV["CONTROLLER"] } if ENV["CONTROLLER"]
1912

2013
OptionParser.new do |opts|
2114
opts.banner = "Usage: rails routes [options]"

railties/test/application/rake_test.rb

+25-42
Original file line numberDiff line numberDiff line change
@@ -132,48 +132,6 @@ def test_rails_routes_calls_the_route_inspector
132132
assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output
133133
end
134134

135-
def test_rails_routes_with_controller_environment
136-
app_file "config/routes.rb", <<-RUBY
137-
Rails.application.routes.draw do
138-
get '/cart', to: 'cart#show'
139-
get '/basketball', to: 'basketball#index'
140-
end
141-
RUBY
142-
143-
output = Dir.chdir(app_path) { `bin/rails routes CONTROLLER=cart` }
144-
assert_equal ["Passing `CONTROLLER` to `bin/rails routes` is deprecated and will be removed in Rails 5.1.",
145-
"Please use `bin/rails routes -c controller_name` instead.",
146-
"Prefix Verb URI Pattern Controller#Action",
147-
" cart GET /cart(.:format) cart#show\n"].join("\n"), output
148-
149-
output = Dir.chdir(app_path) { `bin/rails routes -c cart` }
150-
assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output
151-
end
152-
153-
def test_rails_routes_with_namespaced_controller_environment
154-
app_file "config/routes.rb", <<-RUBY
155-
Rails.application.routes.draw do
156-
namespace :admin do
157-
resource :post
158-
end
159-
end
160-
RUBY
161-
expected_output = [" Prefix Verb URI Pattern Controller#Action",
162-
" new_admin_post GET /admin/post/new(.:format) admin/posts#new",
163-
"edit_admin_post GET /admin/post/edit(.:format) admin/posts#edit",
164-
" admin_post GET /admin/post(.:format) admin/posts#show",
165-
" PATCH /admin/post(.:format) admin/posts#update",
166-
" PUT /admin/post(.:format) admin/posts#update",
167-
" DELETE /admin/post(.:format) admin/posts#destroy",
168-
" POST /admin/post(.:format) admin/posts#create\n"].join("\n")
169-
170-
output = Dir.chdir(app_path) { `bin/rails routes -c Admin::PostController` }
171-
assert_equal expected_output, output
172-
173-
output = Dir.chdir(app_path) { `bin/rails routes -c PostController` }
174-
assert_equal expected_output, output
175-
end
176-
177135
def test_singular_resource_output_in_rake_routes
178136
app_file "config/routes.rb", <<-RUBY
179137
Rails.application.routes.draw do
@@ -232,6 +190,31 @@ def test_rails_routes_with_controller_search_key
232190
assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output
233191
end
234192

193+
def test_rails_routes_with_namespaced_controller_search_key
194+
app_file "config/routes.rb", <<-RUBY
195+
Rails.application.routes.draw do
196+
namespace :admin do
197+
resource :post
198+
end
199+
end
200+
RUBY
201+
expected_output = [" Prefix Verb URI Pattern Controller#Action",
202+
" new_admin_post GET /admin/post/new(.:format) admin/posts#new",
203+
"edit_admin_post GET /admin/post/edit(.:format) admin/posts#edit",
204+
" admin_post GET /admin/post(.:format) admin/posts#show",
205+
" PATCH /admin/post(.:format) admin/posts#update",
206+
" PUT /admin/post(.:format) admin/posts#update",
207+
" DELETE /admin/post(.:format) admin/posts#destroy",
208+
" POST /admin/post(.:format) admin/posts#create\n"].join("\n")
209+
210+
output = Dir.chdir(app_path) { `bin/rails routes -c Admin::PostController` }
211+
assert_equal expected_output, output
212+
213+
output = Dir.chdir(app_path) { `bin/rails routes -c PostController` }
214+
assert_equal expected_output, output
215+
end
216+
217+
235218
def test_rails_routes_displays_message_when_no_routes_are_defined
236219
app_file "config/routes.rb", <<-RUBY
237220
Rails.application.routes.draw do

0 commit comments

Comments
 (0)