Skip to content

Commit 674e780

Browse files
committed
Merge pull request #115 from tableonline/handle_column_limit_with_arrays
Handle array column limits
2 parents 1d96642 + 6b705db commit 674e780

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/annotate/annotate_models.rb

+5-1
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

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

0 commit comments

Comments
 (0)