Skip to content

Commit bb2f573

Browse files
siegfaultmgpnd
authored andcommitted
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.
1 parent 7044ed2 commit bb2f573

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/annotate/annotate_models.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module AnnotateModels
6262

6363
# Don't show limit (#) on these column types
6464
# Example: show "integer" instead of "integer(4)"
65-
NO_LIMIT_COL_TYPES = %w(integer boolean).freeze
65+
NO_LIMIT_COL_TYPES = %w(integer bigint boolean).freeze
6666

6767
# Don't show default value for these column types
6868
NO_DEFAULT_COL_TYPES = %w(json jsonb hstore).freeze
@@ -362,7 +362,7 @@ def get_index_info(klass, options = {})
362362
end
363363

364364
def get_col_type(col)
365-
if col.respond_to?(:bigint?) && col.bigint?
365+
if (col.respond_to?(:bigint?) && col.bigint?) || /\Abigint\b/.match?(col.sql_type)
366366
'bigint'
367367
else
368368
(col.type || col.sql_type).to_s

spec/annotate/annotate_models_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def mock_column(name, type, options = {})
5252
default_options = {
5353
limit: nil,
5454
null: false,
55-
default: nil
55+
default: nil,
56+
sql_type: type
5657
}
5758

5859
stubs = default_options.dup
@@ -184,6 +185,7 @@ def mock_column(name, type, options = {})
184185
mock_column(:id, :integer),
185186
mock_column(:integer, :integer, unsigned?: true),
186187
mock_column(:bigint, :integer, unsigned?: true, bigint?: true),
188+
mock_column(:bigint, :bigint, unsigned?: true),
187189
mock_column(:float, :float, unsigned?: true),
188190
mock_column(:decimal, :decimal, unsigned?: true, precision: 10, scale: 2),
189191
])
@@ -196,6 +198,7 @@ def mock_column(name, type, options = {})
196198
# id :integer not null
197199
# integer :integer unsigned, not null
198200
# bigint :bigint unsigned, not null
201+
# bigint :bigint unsigned, not null
199202
# float :float unsigned, not null
200203
# decimal :decimal(10, 2) unsigned, not null
201204
#

0 commit comments

Comments
 (0)