diff --git a/railties/lib/rails/generators/test_unit/controller/controller_generator.rb b/railties/lib/rails/generators/test_unit/controller/controller_generator.rb index 1a9ac6bf2ab5e121b471d60c6a3607721ec03f8f..88ebd65d6ce7489f8fafca07774f37708f3b3bcb 100644 --- a/railties/lib/rails/generators/test_unit/controller/controller_generator.rb +++ b/railties/lib/rails/generators/test_unit/controller/controller_generator.rb @@ -6,6 +6,8 @@ module TestUnit # :nodoc: module Generators # :nodoc: class ControllerGenerator < Base # :nodoc: argument :actions, type: :array, default: [], banner: "action action" + class_option :skip_routes, type: :boolean + check_class_collision suffix: "ControllerTest" def create_test_files diff --git a/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt b/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt index a69a24e2810bb75574e662e88e6ace7c45c306bb..29e41d0411d73848f1ca9a7173bf29def820a003 100644 --- a/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +++ b/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt @@ -6,7 +6,7 @@ class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest include Engine.routes.url_helpers <% end -%> -<% if actions.empty? -%> +<% if actions.empty? || options[:skip_routes] -%> # test "the truth" do # assert true # end diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 8786756c68d8b1fd38cfdff1def4e92d3c218f72..ae327ad801ccfc484c6b967122e2bac894d57b66 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -75,6 +75,13 @@ def test_skip_routes end end + def test_skip_routes_prevents_generating_tests_with_routes + run_generator ["account", "foo", "--skip-routes"] + assert_file "test/controllers/account_controller_test.rb" do |controller_test| + assert_no_match(/account_foo_(url|path)/, controller_test) + end + end + def test_invokes_default_template_engine_even_with_no_action run_generator ["account"] assert_file "app/views/account"