Skip to content

Commit 6b705db

Browse files
committed
Handle array column limits
if column limit is an array, the values are serialilzed into column attr cf enum_column3 gem
1 parent 8bd159c commit 6b705db

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/annotate/annotate_models.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ def get_schema_info(klass, header, options = {})
120120
col_type << "(#{col.precision}, #{col.scale})"
121121
else
122122
if (col.limit)
123-
col_type << "(#{col.limit})" unless NO_LIMIT_COL_TYPES.include?(col_type)
123+
if col.limit.is_a? Array
124+
attrs << "(#{col.limit.join(', ')})"
125+
else
126+
col_type << "(#{col.limit})" unless NO_LIMIT_COL_TYPES.include?(col_type)
127+
end
124128
end
125129
end
126130

spec/annotate/annotate_models_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ def mock_column(name, type, options={})
8989
# name :string(50) not null
9090
#
9191
92+
EOS
93+
end
94+
it "should get schema info with enum type " do
95+
klass = mock_class(:users, nil, [
96+
mock_column(:id, :integer),
97+
mock_column(:name, :enum, :limit => [:enum1, :enum2])
98+
])
99+
100+
AnnotateModels.get_schema_info(klass, "Schema Info").should eql(<<-EOS)
101+
# Schema Info
102+
#
103+
# Table name: users
104+
#
105+
# id :integer not null
106+
# name :enum not null, (enum1, enum2)
107+
#
108+
92109
EOS
93110
end
94111

0 commit comments

Comments
 (0)