Route generator should be idempotent - closes #22082

This commit is contained in:
Thiago Pinto 2015-10-27 03:34:07 -02:00
parent e76c38ef10
commit a9f9e1dd98
3 changed files with 20 additions and 1 deletions

@ -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`. * Allow passing an environment to `config_for`.
*Simon Eskildsen* *Simon Eskildsen*

@ -235,7 +235,7 @@ def route(routing_code)
sentinel = /\.routes\.draw do\s*\n/m sentinel = /\.routes\.draw do\s*\n/m
in_root do 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
end end

@ -235,6 +235,21 @@ def test_route_should_add_data_to_the_routes_block_in_config_routes
assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/ assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/
end 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 def test_route_should_add_data_with_an_new_line
run_generator run_generator
action :route, "root 'welcome#index'" action :route, "root 'welcome#index'"