Skip to content

Commit 06312d2

Browse files
committed
fix newline option bug
1 parent 58f43d9 commit 06312d2

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/annotate/annotate_models.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
208208
end
209209

210210
info << get_schema_footer_text(klass, options)
211+
212+
info.chomp!("#\n") if options[:with_trailing_newline]
213+
214+
info
211215
end
212216

213217
def get_schema_header_text(klass, options = {})
@@ -228,8 +232,6 @@ def get_schema_footer_text(_klass, options = {})
228232
info << "#--\n"
229233
info << "# #{END_MARK}\n"
230234
info << "#++\n"
231-
elsif options[:with_trailing_newline]
232-
info << "\n"
233235
else
234236
info << "#\n"
235237
end
@@ -461,6 +463,8 @@ def annotate_one_file(file_name, info_block, position, options = {})
461463
magic_comments_block + (old_content.rstrip + "\n\n" + wrapped_info_block)
462464
elsif magic_comments_block.empty?
463465
magic_comments_block + wrapped_info_block + old_content.lstrip
466+
elsif options[:with_trailing_newline]
467+
magic_comments_block + "\n" + wrapped_info_block + old_content
464468
else
465469
magic_comments_block + "\n" + wrapped_info_block + old_content.lstrip
466470
end

spec/lib/annotate/annotate_models_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,12 +1468,12 @@ def mock_column(name, type, options = {})
14681468

14691469
let :expected_result do
14701470
<<~EOS
1471-
# Schema Info
1472-
#
1473-
# Table name: users
1474-
#
1475-
# id :integer not null, primary key
1476-
# name :string(50) not null
1471+
# Schema Info
1472+
#
1473+
# Table name: users
1474+
#
1475+
# id :integer not null, primary key
1476+
# name :string(50) not null
14771477
14781478
EOS
14791479
end

0 commit comments

Comments
 (0)