diff options
author | Arthur Nogueira Neves <github@arthurnn.com> | 2015-03-19 09:19:22 -0400 |
---|---|---|
committer | Arthur Nogueira Neves <github@arthurnn.com> | 2015-03-19 09:19:22 -0400 |
commit | bee9434cdf4f56dc51027a8890cf04f506544735 (patch) | |
tree | 61973f614c9d2b9a097c395273b36a03e44e3144 /railties | |
parent | dfdb08f0923d22b66d6a41e7935ca3a2e02dd15a (diff) | |
parent | 2f23f97b2e58ddb13af30d12c149e55d610a8a26 (diff) | |
download | rails-bee9434cdf4f56dc51027a8890cf04f506544735.tar.gz rails-bee9434cdf4f56dc51027a8890cf04f506544735.tar.bz2 rails-bee9434cdf4f56dc51027a8890cf04f506544735.zip |
Merge pull request #19387 from arthurnn/fix_route_regression
Add a new-line to the end of route method generated code.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 7 | ||||
-rw-r--r-- | railties/lib/rails/generators/actions.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb | 6 | ||||
-rw-r--r-- | railties/test/generators/actions_test.rb | 24 |
4 files changed, 36 insertions, 3 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index b538c81428..f4a8cf86b6 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,10 @@ +* Add a new-line to the end of route method generated code. + + We need to add a `\n`, because we cannot have two routes + in the same line. + + *arthurnn* + * Add `rake initializer` This task prints out initializers for an application. It is useful to diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index c1bc646c65..70a20801a0 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -221,7 +221,7 @@ module Rails sentinel = /\.routes\.draw do\s*\n/m in_root do - inject_into_file 'config/routes.rb', " #{routing_code}", { after: sentinel, verbose: false, force: true } + inject_into_file 'config/routes.rb', " #{routing_code}\n", { after: sentinel, verbose: false, force: true } end end diff --git a/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb b/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb index e4a2bc2b0f..c986f95e67 100644 --- a/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb +++ b/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb @@ -29,8 +29,10 @@ module Rails write("end", route_length - index) end - # route prepends two spaces onto the front of the string that is passed, this corrects that - route route_string[2..-1] + # route prepends two spaces onto the front of the string that is passed, this corrects that. + # Also it adds a \n to the end of each line, as route already adds that + # we need to correct that too. + route route_string[2..-2] end private diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index c6de2c1fb9..c0b88089b3 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -219,6 +219,30 @@ class ActionsTest < Rails::Generators::TestCase assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/ end + def test_route_should_add_data_with_an_new_line + run_generator + action :route, "root 'welcome#index'" + route_path = File.expand_path("config/routes.rb", destination_root) + content = File.read(route_path) + + # Remove all of the comments and blank lines from the routes file + content.gsub!(/^ \#.*\n/, '') + content.gsub!(/^\n/, '') + + File.open(route_path, "wb") { |file| file.write(content) } + assert_file "config/routes.rb", /\.routes\.draw do\n root 'welcome#index'\nend\n\z/ + + action :route, "resources :product_lines" + + routes = <<-F +Rails.application.routes.draw do + resources :product_lines + root 'welcome#index' +end +F + assert_file "config/routes.rb", routes + end + def test_readme run_generator Rails::Generators::AppGenerator.expects(:source_root).times(2).returns(destination_root) |