Skip to content

Commit

Permalink
Api apps scaffold generates routes without new and edit actions
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Apr 20, 2015
1 parent 8f9288c commit ba03cd8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Rails
module Generators
class ResourceRouteGenerator < NamedBase # :nodoc:
class_option :api, type: :boolean,
desc: "Preconfigure smaller stack for API only apps"

# Properly nests namespaces passed into a generator
#
Expand All @@ -22,7 +24,9 @@ def add_resource_route
end

# inserts the primary resource
write("resources :#{file_name.pluralize}", route_length + 1)
resources = "resources :#{file_name.pluralize}"
resources << ", except: [:new, :edit]" if options.api?
write(resources, route_length + 1)

# ends blocks
regular_class_path.each_index do |index|
Expand Down
6 changes: 6 additions & 0 deletions railties/test/generators/resource_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ def test_route_is_removed_on_revoke
assert_no_match(/resources :accounts$/, route)
end
end

def test_api_only_does_not_generate_edit_route
run_generator ["Account", "--api"]

assert_file "config/routes.rb", /resources :accounts, except: \[:new, :edit\]$/
end
end

0 comments on commit ba03cd8

Please sign in to comment.