aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2015-02-03 22:47:59 +0000
committerAndrew White <andyw@pixeltrix.co.uk>2015-02-03 22:53:23 +0000
commit1c59ffca5c8e998aa5cfc0abb594981de23e64c8 (patch)
treedb3386412e4ce4c6a917f64e01bc9f129c69a53a /railties/test/generators
parent158c7eb1d61a28452e0aafd1e05314352eea2749 (diff)
downloadrails-1c59ffca5c8e998aa5cfc0abb594981de23e64c8.tar.gz
rails-1c59ffca5c8e998aa5cfc0abb594981de23e64c8.tar.bz2
rails-1c59ffca5c8e998aa5cfc0abb594981de23e64c8.zip
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.
Diffstat (limited to 'railties/test/generators')
-rw-r--r--railties/test/generators/scaffold_generator_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index 2ec749373b..5ea3ff7444 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -245,6 +245,24 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
assert_file "config/routes.rb", /\.routes\.draw do\s*\|map\|\s*$/
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
run_generator [ "posts", "--no-assets" ]
assert_no_file "app/assets/stylesheets/scaffold.css"