提交 ed67b71e 编写于 作者: J Jonathan Hefner

Prevent generating tests with non-existent routes

This ensures generated tests are not broken by default when invoking the
controller generator with one or more actions and "--skip-routes".
上级 4fe76753
...@@ -6,6 +6,8 @@ module TestUnit # :nodoc: ...@@ -6,6 +6,8 @@ module TestUnit # :nodoc:
module Generators # :nodoc: module Generators # :nodoc:
class ControllerGenerator < Base # :nodoc: class ControllerGenerator < Base # :nodoc:
argument :actions, type: :array, default: [], banner: "action action" argument :actions, type: :array, default: [], banner: "action action"
class_option :skip_routes, type: :boolean
check_class_collision suffix: "ControllerTest" check_class_collision suffix: "ControllerTest"
def create_test_files def create_test_files
......
...@@ -6,7 +6,7 @@ class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest ...@@ -6,7 +6,7 @@ class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers include Engine.routes.url_helpers
<% end -%> <% end -%>
<% if actions.empty? -%> <% if actions.empty? || options[:skip_routes] -%>
# test "the truth" do # test "the truth" do
# assert true # assert true
# end # end
......
...@@ -75,6 +75,13 @@ def test_skip_routes ...@@ -75,6 +75,13 @@ def test_skip_routes
end end
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 def test_invokes_default_template_engine_even_with_no_action
run_generator ["account"] run_generator ["account"]
assert_file "app/views/account" assert_file "app/views/account"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册