Skip to content

Additional new line between magic comment and annotation (AnnotateRou… #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/annotate/annotate_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ def header(options = {})
routes_map = app_routes_map(options)

magic_comments_map, routes_map = extract_magic_comments_from_array(routes_map)

out = []

magic_comments_map.each do |magic_comment|
out << magic_comment
end
out << '' if magic_comments_map.any?

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

Expand Down Expand Up @@ -174,6 +176,7 @@ def self.annotate_routes(header, content, where_header_found, options = {})
magic_comments_map, content = extract_magic_comments_from_array(content)
if %w(before top).include?(options[:position_in_routes])
header = header << '' if content.first != ''
magic_comments_map << '' if magic_comments_map.any?
new_content = magic_comments_map + header + content
else
# Ensure we have adequate trailing newlines at the end of the file to
Expand Down
5 changes: 4 additions & 1 deletion spec/annotate/annotate_routes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def magic_comments_list_each
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(@mock_file).to receive(:puts).with("
#{magic_comment}

# == Route Map
#
# Prefix Verb URI Pattern Controller#Action
Expand All @@ -125,6 +126,7 @@ def magic_comments_list_each
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(@mock_file).to receive(:puts).with("
#{magic_comment}

# ## Route Map
#
# Prefix | Verb | URI Pattern | Controller#Action
Expand All @@ -144,6 +146,7 @@ def magic_comments_list_each
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(@mock_file).to receive(:puts).with("
#{magic_comment}

# START
# == Route Map
#
Expand Down Expand Up @@ -208,7 +211,7 @@ def magic_comments_list_each

magic_comments_list_each do |magic_comment|
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)
AnnotateRoutes.do_annotations(position_in_routes: 'top')
end
Expand Down