mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #15885 from lucasmazza/lm-skip-routes
Add a '--skip-routes' flag for the Controller generator.
This commit is contained in:
commit
5ee87777af
2 changed files with 13 additions and 2 deletions
|
@ -2,6 +2,8 @@ module Rails
|
||||||
module Generators
|
module Generators
|
||||||
class ControllerGenerator < NamedBase # :nodoc:
|
class ControllerGenerator < NamedBase # :nodoc:
|
||||||
argument :actions, type: :array, default: [], banner: "action action"
|
argument :actions, type: :array, default: [], banner: "action action"
|
||||||
|
class_option :skip_routes, type: :boolean, desc: "Dont' add routes to config/routes.rb."
|
||||||
|
|
||||||
check_class_collision suffix: "Controller"
|
check_class_collision suffix: "Controller"
|
||||||
|
|
||||||
def create_controller_files
|
def create_controller_files
|
||||||
|
@ -9,8 +11,10 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_routes
|
def add_routes
|
||||||
actions.reverse.each do |action|
|
unless options[:skip_routes]
|
||||||
route generate_routing_code(action)
|
actions.reverse.each do |action|
|
||||||
|
route generate_routing_code(action)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,13 @@ class ControllerGeneratorTest < Rails::Generators::TestCase
|
||||||
assert_file "config/routes.rb", /get 'account\/foo'/, /get 'account\/bar'/
|
assert_file "config/routes.rb", /get 'account\/foo'/, /get 'account\/bar'/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_skip_routes
|
||||||
|
run_generator ["account", "foo", "--skip-routes"]
|
||||||
|
assert_file "config/routes.rb" do |routes|
|
||||||
|
assert_no_match /get 'account\/foo'/, routes
|
||||||
|
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"
|
||||||
|
|
Loading…
Reference in a new issue