Merge pull request #37778 from jonathanhefner/prevent-tests-with-non-existent-routes

Prevent generating tests with non-existent routes
This commit is contained in:
Eileen M. Uchitelle 2019-11-25 08:56:29 -07:00 committed by GitHub
commit 04fb1a651d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -75,6 +75,13 @@ class ControllerGeneratorTest < Rails::Generators::TestCase
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"