mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #38442 from roramirez/routes-in-scaffold_controller
scaffold_controller: Include the routes when create a generator Controller
This commit is contained in:
commit
428509700b
2 changed files with 24 additions and 0 deletions
|
@ -15,6 +15,8 @@ module Rails
|
|||
class_option :api, type: :boolean,
|
||||
desc: "Generates API controller"
|
||||
|
||||
class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
|
||||
|
||||
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
||||
|
||||
def create_controller_files
|
||||
|
@ -26,6 +28,10 @@ module Rails
|
|||
invoke template_engine unless options.api?
|
||||
end
|
||||
|
||||
hook_for :resource_route, required: true do |route|
|
||||
invoke route unless options.skip_routes?
|
||||
end
|
||||
|
||||
hook_for :test_framework, as: :scaffold
|
||||
|
||||
# Invoke the helper using the controller name (pluralized)
|
||||
|
|
|
@ -12,6 +12,8 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|||
include GeneratorsTestHelper
|
||||
arguments %w(User name:string age:integer)
|
||||
|
||||
setup :copy_routes
|
||||
|
||||
def test_controller_skeleton_is_created
|
||||
run_generator
|
||||
|
||||
|
@ -98,6 +100,22 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_controller_route_are_added
|
||||
run_generator ["Message", "photos:attachments"]
|
||||
|
||||
assert_file "config/routes.rb" do |route|
|
||||
assert_match(/resources :messages$/, route)
|
||||
end
|
||||
end
|
||||
|
||||
def test_controller_route_are_skipped
|
||||
run_generator ["Message", "photos:attachments", "--skip-routes"]
|
||||
|
||||
assert_file "config/routes.rb" do |route|
|
||||
assert_no_match(/resources :messages$/, route)
|
||||
end
|
||||
end
|
||||
|
||||
def test_helper_are_invoked_with_a_pluralized_name
|
||||
run_generator
|
||||
assert_file "app/helpers/users_helper.rb", /module UsersHelper/
|
||||
|
|
Loading…
Reference in a new issue