Commit 365b0126 by Michael Siegfried Committed by Cuong Tran

Allow bigint annotations in rails 4. (#569)

In rails 4, columns do not respond to `bigint?`. However, in both rails 4 and rails 5, columns do respond to `sql_type`. This way, annotations should work in both versions.
parent 96bcf6c0
......@@ -62,7 +62,7 @@ module AnnotateModels
# Don't show limit (#) on these column types
# Example: show "integer" instead of "integer(4)"
NO_LIMIT_COL_TYPES = %w(integer boolean).freeze
NO_LIMIT_COL_TYPES = %w(integer bigint boolean).freeze
# Don't show default value for these column types
NO_DEFAULT_COL_TYPES = %w(json jsonb hstore).freeze
......@@ -362,7 +362,7 @@ module AnnotateModels
end
def get_col_type(col)
if col.respond_to?(:bigint?) && col.bigint?
if (col.respond_to?(:bigint?) && col.bigint?) || /\Abigint\b/.match?(col.sql_type)
'bigint'
else
(col.type || col.sql_type).to_s
......
......@@ -52,7 +52,8 @@ describe AnnotateModels do
default_options = {
limit: nil,
null: false,
default: nil
default: nil,
sql_type: type
}
stubs = default_options.dup
......@@ -184,6 +185,7 @@ EOS
mock_column(:id, :integer),
mock_column(:integer, :integer, unsigned?: true),
mock_column(:bigint, :integer, unsigned?: true, bigint?: true),
mock_column(:bigint, :bigint, unsigned?: true),
mock_column(:float, :float, unsigned?: true),
mock_column(:decimal, :decimal, unsigned?: true, precision: 10, scale: 2),
])
......@@ -196,6 +198,7 @@ EOS
# id :integer not null
# integer :integer unsigned, not null
# bigint :bigint unsigned, not null
# bigint :bigint unsigned, not null
# float :float unsigned, not null
# decimal :decimal(10, 2) unsigned, not null
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment