1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #22083 from thejamespinto/idempotent-route-generator

Route generator should be idempotent
This commit is contained in:
Andrew White 2015-11-01 09:01:49 +00:00
commit d53de10cb3
3 changed files with 20 additions and 1 deletions

View file

@ -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*

View file

@ -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

View file

@ -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'"