diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2015-02-05 17:47:36 +0000 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2015-02-05 17:54:23 +0000 |
commit | 80838d9bd548d2b15f6692e84cbe30c697e54b4a (patch) | |
tree | 16b30c36df0e2c6fe8fd114b849561eff429f804 | |
parent | da9038eaa5d19c77c734a044c6b35d7bfac01104 (diff) | |
download | rails-80838d9bd548d2b15f6692e84cbe30c697e54b4a.tar.gz rails-80838d9bd548d2b15f6692e84cbe30c697e54b4a.tar.bz2 rails-80838d9bd548d2b15f6692e84cbe30c697e54b4a.zip |
Force generated route to be inserted
Thor isn't very discerning over whether some content is present when passed
to `inject_into_file`, e.g. a commented out route is detected as being present.
So to prevent people scratching their heads as to why a route hasn't appeared
it's better to fall on the side of having duplicate routes.
-rw-r--r-- | railties/CHANGELOG.md | 4 | ||||
-rw-r--r-- | railties/lib/rails/generators/actions.rb | 2 | ||||
-rw-r--r-- | railties/test/generators/scaffold_generator_test.rb | 5 |
3 files changed, 10 insertions, 1 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index a202325e88..a3f24f854d 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Force generated routes to be inserted into routes.rb + + *Andrew White* + * Don't remove all line endings from routes.rb when revoking scaffold. Fixes #15913. diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index e39a45f4c9..c1bc646c65 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 } + inject_into_file 'config/routes.rb', " #{routing_code}", { after: sentinel, verbose: false, force: true } end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 5ea3ff7444..ee06802874 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -263,6 +263,11 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "config/routes.rb", /\.routes\.draw do\nend\n\z/ end + def test_scaffold_generator_ignores_commented_routes + run_generator ["product"] + assert_file "config/routes.rb", /\.routes\.draw do\n resources :products\n/ + end + def test_scaffold_generator_no_assets_with_switch_no_assets run_generator [ "posts", "--no-assets" ] assert_no_file "app/assets/stylesheets/scaffold.css" |