aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorYuji Yaginuma <yuuji.yaginuma@gmail.com>2018-02-22 08:39:37 +0900
committerYuji Yaginuma <yuuji.yaginuma@gmail.com>2018-02-22 08:39:37 +0900
commit651c2492f079cc2e37bf8e93a9fd23bde1e5349e (patch)
treeb259fadcebddd2cda32074d299cb6b717c32fa64 /railties
parent63d530c5e68a8cf53603744789f53ccbc7ac1a0e (diff)
downloadrails-651c2492f079cc2e37bf8e93a9fd23bde1e5349e.tar.gz
rails-651c2492f079cc2e37bf8e93a9fd23bde1e5349e.tar.bz2
rails-651c2492f079cc2e37bf8e93a9fd23bde1e5349e.zip
Do not add routes when actions are not specified
Since #30241, if namepsace is specified, routes will be generated even if there is no actions. However, it seems that this behavior is not intentionally added behavior. As with 5.1, routes should not be generated if actions are not specified. Fixes #32072.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/rails/controller/controller_generator.rb1
-rw-r--r--railties/test/generators/controller_generator_test.rb7
2 files changed, 8 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb
index 6d45d6e8f8..6e2495d45f 100644
--- a/railties/lib/rails/generators/rails/controller/controller_generator.rb
+++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb
@@ -16,6 +16,7 @@ module Rails
def add_routes
return if options[:skip_routes]
+ return if actions.empty?
route generate_routing_code
end
diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb
index a3218951a6..91e4a86775 100644
--- a/railties/test/generators/controller_generator_test.rb
+++ b/railties/test/generators/controller_generator_test.rb
@@ -109,4 +109,11 @@ class ControllerGeneratorTest < Rails::Generators::TestCase
assert_match(/^ namespace :admin do\n get 'dashboard\/index'\n get 'dashboard\/show'\n end$/, route)
end
end
+
+ def test_does_not_add_routes_when_action_is_not_specified
+ run_generator ["admin/dashboard"]
+ assert_file "config/routes.rb" do |routes|
+ assert_no_match(/namespace :admin/, routes)
+ end
+ end
end