Skip to content

Commit c4ecc11

Browse files
sashabelozerovctran
authored andcommitted
Additional new line between magic comment and annotation (AnnotateRoutes) (#524)
1 parent 4db90ef commit c4ecc11

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/annotate/annotate_routes.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ def header(options = {})
3939
routes_map = app_routes_map(options)
4040

4141
magic_comments_map, routes_map = extract_magic_comments_from_array(routes_map)
42+
4243
out = []
4344

4445
magic_comments_map.each do |magic_comment|
4546
out << magic_comment
4647
end
48+
out << '' if magic_comments_map.any?
4749

4850
out += ["# #{options[:wrapper_open]}"] if options[:wrapper_open]
4951

@@ -174,6 +176,7 @@ def self.annotate_routes(header, content, where_header_found, options = {})
174176
magic_comments_map, content = extract_magic_comments_from_array(content)
175177
if %w(before top).include?(options[:position_in_routes])
176178
header = header << '' if content.first != ''
179+
magic_comments_map << '' if magic_comments_map.any?
177180
new_content = magic_comments_map + header + content
178181
else
179182
# Ensure we have adequate trailing newlines at the end of the file to

spec/annotate/annotate_routes_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def magic_comments_list_each
106106
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
107107
expect(@mock_file).to receive(:puts).with("
108108
#{magic_comment}
109+
109110
# == Route Map
110111
#
111112
# Prefix Verb URI Pattern Controller#Action
@@ -125,6 +126,7 @@ def magic_comments_list_each
125126
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
126127
expect(@mock_file).to receive(:puts).with("
127128
#{magic_comment}
129+
128130
# ## Route Map
129131
#
130132
# Prefix | Verb | URI Pattern | Controller#Action
@@ -144,6 +146,7 @@ def magic_comments_list_each
144146
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
145147
expect(@mock_file).to receive(:puts).with("
146148
#{magic_comment}
149+
147150
# START
148151
# == Route Map
149152
#
@@ -208,7 +211,7 @@ def magic_comments_list_each
208211

209212
magic_comments_list_each do |magic_comment|
210213
expect(File).to receive(:read).with(ROUTE_FILE).and_return("#{magic_comment}\nSomething")
211-
expect(@mock_file).to receive(:puts).with("#{magic_comment}\n# == Route Map\n#\n\nSomething\n")
214+
expect(@mock_file).to receive(:puts).with("#{magic_comment}\n\n# == Route Map\n#\n\nSomething\n")
212215
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
213216
AnnotateRoutes.do_annotations(position_in_routes: 'top')
214217
end

0 commit comments

Comments
 (0)