Commit 5177edd4 by cuong.tran

Ignore default value for json type since that can break indentation, #320

parent 5c9674fe
......@@ -59,6 +59,9 @@ module AnnotateModels
# Example: show "integer" instead of "integer(4)"
NO_LIMIT_COL_TYPES = ["integer", "boolean"]
# Don't show default value for these column types
NO_DEFAULT_COL_TYPES = ["json", "jsonb"]
class << self
def model_dir
@model_dir.is_a?(Array) ? @model_dir : [@model_dir || "app/models"]
......@@ -198,7 +201,7 @@ module AnnotateModels
col_type = (col.type || col.sql_type).to_s
attrs = []
attrs << "default(#{schema_default(klass, col)})" unless col.default.nil? || col_type == "jsonb"
attrs << "default(#{schema_default(klass, col)})" unless col.default.nil? || NO_DEFAULT_COL_TYPES.include?(col_type)
attrs << "not null" unless col.null
attrs << "primary key" if klass.primary_key && (klass.primary_key.is_a?(Array) ? klass.primary_key.collect{|c|c.to_sym}.include?(col.name.to_sym) : col.name.to_sym == klass.primary_key.to_sym)
......
......@@ -150,6 +150,25 @@ EOS
EOS
end
it "should ignore default value of json columns " do
klass = mock_class(:users, nil, [
mock_column(:id, :integer),
mock_column(:profile, :json, :default => '{}'),
mock_column(:settings, :jsonb, :default => '{}')
])
expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS)
# Schema Info
#
# Table name: users
#
# id :integer not null
# profile :json not null
# settings :jsonb not null
#
EOS
end
it "should get foreign key info" do
klass = mock_class(:users, :id, [
mock_column(:id, :integer),
......
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