diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2015-04-14 08:58:21 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2015-04-14 09:34:51 +0900 |
commit | d2be2a9166815f862dad24d160c643589e80b259 (patch) | |
tree | ce63551cf743499e35f05fc02c3959b5be54ad98 /railties | |
parent | ea97c763c18b4f7534589665c73d501fcec229a3 (diff) | |
download | rails-d2be2a9166815f862dad24d160c643589e80b259.tar.gz rails-d2be2a9166815f862dad24d160c643589e80b259.tar.bz2 rails-d2be2a9166815f862dad24d160c643589e80b259.zip |
fix indent in routes when using namespaced controllers
Before:
namespace :foo do
namespace :bar do
get 'baz/index'
end
end
After:
namespace :foo do
namespace :bar do
get 'baz/index'
end
end
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/generators/rails/controller/controller_generator.rb | 7 | ||||
-rw-r--r-- | railties/test/generators/controller_generator_test.rb | 4 |
2 files changed, 7 insertions, 4 deletions
diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb index df615c88b5..6c583e5811 100644 --- a/railties/lib/rails/generators/rails/controller/controller_generator.rb +++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb @@ -13,7 +13,8 @@ module Rails def add_routes unless options[:skip_routes] actions.reverse_each do |action| - route generate_routing_code(action) + # route prepends two spaces onto the front of the string that is passed, this corrects that. + route generate_routing_code(action)[2..-1] end end end @@ -36,12 +37,12 @@ module Rails # namespace :foo do # namespace :bar do namespace_ladder = regular_class_path.each_with_index.map do |ns, i| - indent("namespace :#{ns} do\n", i * 2) + indent(" namespace :#{ns} do\n", i * 2) end.join # Create route # get 'baz/index' - route = indent(%{get '#{file_name}/#{action}'\n}, depth * 2) + route = indent(%{ get '#{file_name}/#{action}'\n}, depth * 2) # Create `end` ladder # end diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index a7d56dd352..1351151afb 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -96,6 +96,8 @@ class ControllerGeneratorTest < Rails::Generators::TestCase def test_namespaced_routes_are_created_in_routes run_generator ["admin/dashboard", "index"] - assert_file "config/routes.rb", /namespace :admin do\n\s+get 'dashboard\/index'\n/ + assert_file "config/routes.rb" do |route| + assert_match(/^ namespace :admin do\n get 'dashboard\/index'\n end$/, route) + end end end |