mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Don't remove all line endings from routes.rb
When there is a single scaffold in the routes.rb with no other lines then revoking/destroying it will create a routes.rb file with a syntax error. This is because the sentinel for the Thor `route` action didn't include the newline but the logged route code did. The fix is to add the newline to the sentinel and remove it from the the logged route code. Fixes #15913.
This commit is contained in:
parent
158c7eb1d6
commit
1c59ffca5c
3 changed files with 26 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
* Don't remove all line endings from routes.rb when revoking scaffold.
|
||||||
|
|
||||||
|
Fixes #15913.
|
||||||
|
|
||||||
|
*Andrew White*
|
||||||
|
|
||||||
* Rename `--skip-test-unit` option to `--skip-test` in app generator
|
* Rename `--skip-test-unit` option to `--skip-test` in app generator
|
||||||
|
|
||||||
*Melanie Gilman*
|
*Melanie Gilman*
|
||||||
|
|
|
@ -218,10 +218,10 @@ module Rails
|
||||||
# route "root 'welcome#index'"
|
# route "root 'welcome#index'"
|
||||||
def route(routing_code)
|
def route(routing_code)
|
||||||
log :route, routing_code
|
log :route, routing_code
|
||||||
sentinel = /\.routes\.draw do\s*$/
|
sentinel = /\.routes\.draw do\s*\n/m
|
||||||
|
|
||||||
in_root do
|
in_root do
|
||||||
inject_into_file 'config/routes.rb', "\n #{routing_code}", { after: sentinel, verbose: false }
|
inject_into_file 'config/routes.rb', " #{routing_code}", { after: sentinel, verbose: false }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -245,6 +245,24 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
||||||
assert_file "config/routes.rb", /\.routes\.draw do\s*\|map\|\s*$/
|
assert_file "config/routes.rb", /\.routes\.draw do\s*\|map\|\s*$/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_scaffold_generator_on_revoke_does_not_mutilate_routes
|
||||||
|
run_generator
|
||||||
|
|
||||||
|
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 resources :product_lines\nend\n\z/
|
||||||
|
|
||||||
|
run_generator ["product_line"], :behavior => :revoke
|
||||||
|
|
||||||
|
assert_file "config/routes.rb", /\.routes\.draw do\nend\n\z/
|
||||||
|
end
|
||||||
|
|
||||||
def test_scaffold_generator_no_assets_with_switch_no_assets
|
def test_scaffold_generator_no_assets_with_switch_no_assets
|
||||||
run_generator [ "posts", "--no-assets" ]
|
run_generator [ "posts", "--no-assets" ]
|
||||||
assert_no_file "app/assets/stylesheets/scaffold.css"
|
assert_no_file "app/assets/stylesheets/scaffold.css"
|
||||||
|
|
Loading…
Reference in a new issue