From 1fd9cdfda6c4e4473667cb6e28b8097607abc765 Mon Sep 17 00:00:00 2001 From: Volmer Date: Mon, 4 Jul 2016 21:58:20 -0400 Subject: Deprecate usage of nil as route path In Rails 4 these kind of routes used to work: ```ruby scope '/*id', controller: :builds, as: :build do get action: :show end ``` But since 1a830cbd830c7f80936dff7e3c8b26f60dcc371d, routes are only created for paths specified as strings or symbols. Implicit `nil` paths are just ignored, with no deprecation warnings or errors. Routes are simply not created. This come as a surprise for people migrating to Rails 5, since the lack of logs or errors makes hard to understand where the problem is. This commit introduces a deprecation warning in case of path as `nil`, while still allowing the route definition. --- actionpack/lib/action_dispatch/routing/mapper.rb | 6 ++++++ actionpack/test/dispatch/routing_test.rb | 7 +++++++ 2 files changed, 13 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index e2cf75da3a..73b4864e45 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1562,6 +1562,12 @@ module ActionDispatch options = path path, to = options.find { |name, _value| name.is_a?(String) } + if path.nil? + ActiveSupport::Deprecation.warn 'Omitting the route path is deprecated. '\ + 'Specify the path with a String or a Symbol instead.' + path = '' + end + case to when Symbol options[:action] = to diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 75fdc9469f..d54cdf7247 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -373,6 +373,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest post "create", :as => "" put "update" get "remove", :action => :destroy, :as => :remove + tc.assert_deprecated do + get action: :show, as: :show + end end end @@ -391,6 +394,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get '/pagemark/remove' assert_equal 'pagemarks#destroy', @response.body assert_equal '/pagemark/remove', pagemark_remove_path + + get '/pagemark' + assert_equal 'pagemarks#show', @response.body + assert_equal '/pagemark', pagemark_show_path end def test_admin -- cgit v1.2.3