Commit 1992120e by Tim Perkins Committed by Cuong Tran

Do not add whitespace after magic comments when annotating at position after/bottom (#584)

parent 26142667
...@@ -529,8 +529,10 @@ module AnnotateModels ...@@ -529,8 +529,10 @@ module AnnotateModels
new_content = if %w(after bottom).include?(options[position].to_s) new_content = if %w(after bottom).include?(options[position].to_s)
magic_comments_block + (old_content.rstrip + "\n\n" + wrapped_info_block) magic_comments_block + (old_content.rstrip + "\n\n" + wrapped_info_block)
else elsif magic_comments_block.empty?
magic_comments_block + wrapped_info_block + "\n" + old_content magic_comments_block + wrapped_info_block + "\n" + old_content
else
magic_comments_block + "\n" + wrapped_info_block + "\n" + old_content
end end
else else
# replace the old annotation with the new one # replace the old annotation with the new one
...@@ -554,7 +556,7 @@ module AnnotateModels ...@@ -554,7 +556,7 @@ module AnnotateModels
magic_comments = content.scan(magic_comment_matcher).flatten.compact magic_comments = content.scan(magic_comment_matcher).flatten.compact
if magic_comments.any? if magic_comments.any?
magic_comments.join + "\n" magic_comments.join
else else
'' ''
end end
......
...@@ -1697,7 +1697,7 @@ end ...@@ -1697,7 +1697,7 @@ end
end end
end end
it 'adds an empty line between magic comments and model file content (position :after)' do it 'does not change whitespace between magic comments and model file content (position :after)' do
content = "class User < ActiveRecord::Base\nend\n" content = "class User < ActiveRecord::Base\nend\n"
magic_comments_list_each do |magic_comment| magic_comments_list_each do |magic_comment|
model_file_name, = write_model 'user.rb', "#{magic_comment}\n#{content}" model_file_name, = write_model 'user.rb', "#{magic_comment}\n#{content}"
...@@ -1705,7 +1705,7 @@ end ...@@ -1705,7 +1705,7 @@ end
annotate_one_file position: :after annotate_one_file position: :after
schema_info = AnnotateModels.get_schema_info(@klass, '== Schema Info') schema_info = AnnotateModels.get_schema_info(@klass, '== Schema Info')
expect(File.read(model_file_name)).to eq("#{magic_comment}\n\n#{content}\n#{schema_info}") expect(File.read(model_file_name)).to eq("#{magic_comment}\n#{content}\n#{schema_info}")
end end
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