Commit c4ecc117 by Alexander Belozerov Committed by Cuong Tran

Additional new line between magic comment and annotation (AnnotateRoutes) (#524)

parent 4db90efe
...@@ -39,11 +39,13 @@ module AnnotateRoutes ...@@ -39,11 +39,13 @@ module AnnotateRoutes
routes_map = app_routes_map(options) routes_map = app_routes_map(options)
magic_comments_map, routes_map = extract_magic_comments_from_array(routes_map) magic_comments_map, routes_map = extract_magic_comments_from_array(routes_map)
out = [] out = []
magic_comments_map.each do |magic_comment| magic_comments_map.each do |magic_comment|
out << magic_comment out << magic_comment
end end
out << '' if magic_comments_map.any?
out += ["# #{options[:wrapper_open]}"] if options[:wrapper_open] out += ["# #{options[:wrapper_open]}"] if options[:wrapper_open]
...@@ -174,6 +176,7 @@ module AnnotateRoutes ...@@ -174,6 +176,7 @@ module AnnotateRoutes
magic_comments_map, content = extract_magic_comments_from_array(content) magic_comments_map, content = extract_magic_comments_from_array(content)
if %w(before top).include?(options[:position_in_routes]) if %w(before top).include?(options[:position_in_routes])
header = header << '' if content.first != '' header = header << '' if content.first != ''
magic_comments_map << '' if magic_comments_map.any?
new_content = magic_comments_map + header + content new_content = magic_comments_map + header + content
else else
# Ensure we have adequate trailing newlines at the end of the file to # Ensure we have adequate trailing newlines at the end of the file to
......
...@@ -106,6 +106,7 @@ describe AnnotateRoutes do ...@@ -106,6 +106,7 @@ describe AnnotateRoutes do
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(@mock_file).to receive(:puts).with(" expect(@mock_file).to receive(:puts).with("
#{magic_comment} #{magic_comment}
# == Route Map # == Route Map
# #
# Prefix Verb URI Pattern Controller#Action # Prefix Verb URI Pattern Controller#Action
...@@ -125,6 +126,7 @@ describe AnnotateRoutes do ...@@ -125,6 +126,7 @@ describe AnnotateRoutes do
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(@mock_file).to receive(:puts).with(" expect(@mock_file).to receive(:puts).with("
#{magic_comment} #{magic_comment}
# ## Route Map # ## Route Map
# #
# Prefix | Verb | URI Pattern | Controller#Action # Prefix | Verb | URI Pattern | Controller#Action
...@@ -144,6 +146,7 @@ describe AnnotateRoutes do ...@@ -144,6 +146,7 @@ describe AnnotateRoutes do
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(@mock_file).to receive(:puts).with(" expect(@mock_file).to receive(:puts).with("
#{magic_comment} #{magic_comment}
# START # START
# == Route Map # == Route Map
# #
...@@ -208,7 +211,7 @@ describe AnnotateRoutes do ...@@ -208,7 +211,7 @@ describe AnnotateRoutes do
magic_comments_list_each do |magic_comment| magic_comments_list_each do |magic_comment|
expect(File).to receive(:read).with(ROUTE_FILE).and_return("#{magic_comment}\nSomething") expect(File).to receive(:read).with(ROUTE_FILE).and_return("#{magic_comment}\nSomething")
expect(@mock_file).to receive(:puts).with("#{magic_comment}\n# == Route Map\n#\n\nSomething\n") expect(@mock_file).to receive(:puts).with("#{magic_comment}\n\n# == Route Map\n#\n\nSomething\n")
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED) expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
AnnotateRoutes.do_annotations(position_in_routes: 'top') AnnotateRoutes.do_annotations(position_in_routes: 'top')
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment