Skip to content

Commit 8f323de

Browse files
committed
Add unsigned support for numeric data types
1 parent 65af43e commit 8f323de

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

.rubocop_todo.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ Lint/UselessAccessModifier:
8181

8282
# Offense count: 16
8383
Metrics/AbcSize:
84-
Max: 154
84+
Max: 156
8585

8686
# Offense count: 2
8787
Metrics/BlockNesting:
8888
Max: 4
8989

9090
# Offense count: 7
9191
Metrics/CyclomaticComplexity:
92-
Max: 36
92+
Max: 38
9393

9494
# Offense count: 344
9595
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
@@ -100,16 +100,16 @@ Metrics/LineLength:
100100
# Offense count: 24
101101
# Configuration parameters: CountComments.
102102
Metrics/MethodLength:
103-
Max: 83
103+
Max: 84
104104

105105
# Offense count: 2
106106
# Configuration parameters: CountComments.
107107
Metrics/ModuleLength:
108-
Max: 522
108+
Max: 523
109109

110110
# Offense count: 7
111111
Metrics/PerceivedComplexity:
112-
Max: 43
112+
Max: 45
113113

114114
# Offense count: 1
115115
Style/AccessorMethodName:

lib/annotate/annotate_models.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def get_schema_info(klass, header, options = {})
221221

222222
attrs = []
223223
attrs << "default(#{schema_default(klass, col)})" unless col.default.nil? || NO_DEFAULT_COL_TYPES.include?(col_type)
224+
attrs << 'unsigned' if col.respond_to?(:unsigned?) && col.unsigned?
224225
attrs << 'not null' unless col.null
225226
attrs << 'primary key' if klass.primary_key && (klass.primary_key.is_a?(Array) ? klass.primary_key.collect(&:to_sym).include?(col.name.to_sym) : col.name.to_sym == klass.primary_key.to_sym)
226227

spec/annotate/annotate_models_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def mock_column(name, type, options={})
118118
#
119119
EOS
120120
end
121+
121122
it "should get schema info with enum type " do
122123
klass = mock_class(:users, nil, [
123124
mock_column(:id, :integer),
@@ -135,6 +136,29 @@ def mock_column(name, type, options={})
135136
EOS
136137
end
137138

139+
it "should get schema info with unsigned" do
140+
klass = mock_class(:users, nil, [
141+
mock_column(:id, :integer),
142+
mock_column(:integer, :integer, :unsigned? => true),
143+
mock_column(:bigint, :bigint, :unsigned? => true),
144+
mock_column(:float, :float, :unsigned? => true),
145+
mock_column(:decimal, :decimal, :unsigned? => true, :precision => 10, :scale => 2),
146+
])
147+
148+
expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS)
149+
# Schema Info
150+
#
151+
# Table name: users
152+
#
153+
# id :integer not null
154+
# integer :integer unsigned, not null
155+
# bigint :bigint unsigned, not null
156+
# float :float unsigned, not null
157+
# decimal :decimal(10, 2) unsigned, not null
158+
#
159+
EOS
160+
end
161+
138162
it "should get schema info for integer and boolean with default" do
139163
klass = mock_class(:users, :id, [
140164
mock_column(:id, :integer),

0 commit comments

Comments
 (0)