Skip to content

Commit 55c23eb

Browse files
colbymelvindrwl
authored andcommitted
Fix annotations for columns with long data types (#622)
Handle potential negative padding in `#mb_chars_ljust` when having a `col_length` > 16, the default hardcoded value of `bare_type_allowance`.
1 parent b56e89d commit 55c23eb

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/annotate/annotate_models.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,11 @@ def width(string)
910910
def mb_chars_ljust(string, length)
911911
string = string.to_s
912912
padding = length - width(string)
913-
string + (' ' * padding)
913+
if padding > 0
914+
string + (' ' * padding)
915+
else
916+
string[0..length-1]
917+
end
914918
end
915919
end
916920

spec/annotate/annotate_models_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,8 @@ def self.when_called_with(options = {})
943943
[:active, :boolean, { limit: 1, comment: 'ACTIVE' }],
944944
[:name, :string, { limit: 50, comment: 'NAME' }],
945945
[:notes, :text, { limit: 55, comment: 'NOTES' }],
946-
[:no_comment, :text, { limit: 20, comment: nil }]
946+
[:no_comment, :text, { limit: 20, comment: nil }],
947+
[:location, :geometry_collection, { limit: nil, comment: nil }]
947948
]
948949

949950
when_called_with with_comment: 'yes',
@@ -958,6 +959,7 @@ def self.when_called_with(options = {})
958959
# name(NAME) :string(50) not null
959960
# notes(NOTES) :text(55) not null
960961
# no_comment :text(20) not null
962+
# location :geometry_collect not null
961963
#
962964
EOS
963965

0 commit comments

Comments
 (0)