aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2015-11-01 09:01:49 +0000
committerAndrew White <pixeltrix@users.noreply.github.com>2015-11-01 09:01:49 +0000
commitd53de10cb35e9710389391cf5cd63340745a0ab8 (patch)
tree55571e776401ef25fd8c3e49d67a0a7956b75706
parentb217354dbbbbb49a020b0073ebb62c5cd2d96140 (diff)
parenta9f9e1dd98cc2dd161d51d6902aac90b275fee05 (diff)
downloadrails-d53de10cb35e9710389391cf5cd63340745a0ab8.tar.gz
rails-d53de10cb35e9710389391cf5cd63340745a0ab8.tar.bz2
rails-d53de10cb35e9710389391cf5cd63340745a0ab8.zip
Merge pull request #22083 from thejamespinto/idempotent-route-generator
Route generator should be idempotent
-rw-r--r--railties/CHANGELOG.md4
-rw-r--r--railties/lib/rails/generators/actions.rb2
-rw-r--r--railties/test/generators/actions_test.rb15
3 files changed, 20 insertions, 1 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 967f850ea0..85e71b6c5c 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Route generator should be idempotent
+ running generators several times no longer require you to cleanup routes.rb
+
+ *Thiago Pinto*
* Allow passing an environment to `config_for`.
*Simon Eskildsen*
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index b4356f71e0..5bbd2f1aed 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -235,7 +235,7 @@ module Rails
sentinel = /\.routes\.draw do\s*\n/m
in_root do
- inject_into_file 'config/routes.rb', " #{routing_code}\n", { after: sentinel, verbose: false, force: true }
+ inject_into_file 'config/routes.rb', " #{routing_code}\n", { after: sentinel, verbose: false, force: false }
end
end
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index fabba555ef..b4fbea4af4 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -235,6 +235,21 @@ class ActionsTest < Rails::Generators::TestCase
assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/
end
+ def test_route_should_be_idempotent
+ run_generator
+ route_path = File.expand_path('config/routes.rb', destination_root)
+
+ # runs first time, not asserting
+ action :route, "root 'welcome#index'"
+ content_1 = File.read(route_path)
+
+ # runs second time
+ action :route, "root 'welcome#index'"
+ content_2 = File.read(route_path)
+
+ assert_equal content_1, content_2
+ end
+
def test_route_should_add_data_with_an_new_line
run_generator
action :route, "root 'welcome#index'"