From d8ea64fd57afba412906671543d93f4a86a817e0 Mon Sep 17 00:00:00 2001 From: Alexander Belozerov Date: Fri, 20 Oct 2017 20:19:06 +0600 Subject: [PATCH] Additional new line between magic comment and annotation (AnnotateRoutes) --- lib/annotate/annotate_routes.rb | 3 +++ spec/annotate/annotate_routes_spec.rb | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/annotate/annotate_routes.rb b/lib/annotate/annotate_routes.rb index e04960113..276c2cbc1 100644 --- a/lib/annotate/annotate_routes.rb +++ b/lib/annotate/annotate_routes.rb @@ -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] @@ -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 diff --git a/spec/annotate/annotate_routes_spec.rb b/spec/annotate/annotate_routes_spec.rb index 005f1ff70..1a34bbee0 100644 --- a/spec/annotate/annotate_routes_spec.rb +++ b/spec/annotate/annotate_routes_spec.rb @@ -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 @@ -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 @@ -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 # @@ -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