Commit a8162558 by Kyle Zhao Committed by Cuong Tran

FIX: Ensure only one line is around the annotation (#669)

parent 693abdd2
......@@ -540,9 +540,9 @@ module AnnotateModels
new_content = if %w(after bottom).include?(options[position].to_s)
magic_comments_block + (old_content.rstrip + "\n\n" + wrapped_info_block)
elsif magic_comments_block.empty?
magic_comments_block + wrapped_info_block + "\n" + old_content
magic_comments_block + wrapped_info_block + "\n" + old_content.lstrip
else
magic_comments_block + "\n" + wrapped_info_block + "\n" + old_content
magic_comments_block + "\n" + wrapped_info_block + "\n" + old_content.lstrip
end
else
# replace the old annotation with the new one
......
......@@ -1803,6 +1803,18 @@ end
end
end
it 'only keeps a single empty line around the annotation (position :before)' do
content = "class User < ActiveRecord::Base\nend\n"
magic_comments_list_each do |magic_comment|
schema_info = AnnotateModels.get_schema_info(@klass, '== Schema Info')
model_file_name, = write_model 'user.rb', "#{magic_comment}\n\n\n\n#{content}"
annotate_one_file position: :before
expect(File.read(model_file_name)).to eq("#{magic_comment}\n\n#{schema_info}\n#{content}")
end
end
it 'does not change whitespace between magic comments and model file content (position :after)' do
content = "class User < ActiveRecord::Base\nend\n"
magic_comments_list_each do |magic_comment|
......
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