Skip to content

Add unsigned support for numeric data types #390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ Lint/UselessAccessModifier:

# Offense count: 16
Metrics/AbcSize:
Max: 154
Max: 156

# Offense count: 2
Metrics/BlockNesting:
Max: 4

# Offense count: 7
Metrics/CyclomaticComplexity:
Max: 36
Max: 38

# Offense count: 344
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
Expand All @@ -100,16 +100,16 @@ Metrics/LineLength:
# Offense count: 24
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 83
Max: 84

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 522
Max: 523

# Offense count: 7
Metrics/PerceivedComplexity:
Max: 43
Max: 45

# Offense count: 1
Style/AccessorMethodName:
Expand Down
1 change: 1 addition & 0 deletions lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ def get_schema_info(klass, header, options = {})

attrs = []
attrs << "default(#{schema_default(klass, col)})" unless col.default.nil? || NO_DEFAULT_COL_TYPES.include?(col_type)
attrs << 'unsigned' if col.respond_to?(:unsigned?) && col.unsigned?
attrs << 'not null' unless col.null
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)

Expand Down
24 changes: 24 additions & 0 deletions spec/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def mock_column(name, type, options={})
#
EOS
end

it "should get schema info with enum type " do
klass = mock_class(:users, nil, [
mock_column(:id, :integer),
Expand All @@ -135,6 +136,29 @@ def mock_column(name, type, options={})
EOS
end

it "should get schema info with unsigned" do
klass = mock_class(:users, nil, [
mock_column(:id, :integer),
mock_column(:integer, :integer, :unsigned? => true),
mock_column(:bigint, :bigint, :unsigned? => true),
mock_column(:float, :float, :unsigned? => true),
mock_column(:decimal, :decimal, :unsigned? => true, :precision => 10, :scale => 2),
])

expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS)
# Schema Info
#
# Table name: users
#
# id :integer not null
# integer :integer unsigned, not null
# bigint :bigint unsigned, not null
# float :float unsigned, not null
# decimal :decimal(10, 2) unsigned, not null
#
EOS
end

it "should get schema info for integer and boolean with default" do
klass = mock_class(:users, :id, [
mock_column(:id, :integer),
Expand Down