diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index f286e03a9..69da7e862 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -213,7 +213,7 @@ def quote(value) end def schema_default(klass, column) - quote(klass.columns.find { |x| x.name.to_s == column.name.to_s }.try(:default)) + quote(klass.column_defaults[column.name]) end def retrieve_indexes_from_table(klass) diff --git a/spec/integration/rails_5.2.4.1_spec.rb b/spec/integration/rails_5.2.4.1_spec.rb index 6fe8e9ebd..f2957d6dd 100644 --- a/spec/integration/rails_5.2.4.1_spec.rb +++ b/spec/integration/rails_5.2.4.1_spec.rb @@ -34,8 +34,8 @@ +# +# id :integer not null, primary key +# content :string - +# count :integer default("0") - +# status :boolean default("0") + +# count :integer default(0) + +# status :boolean default(FALSE) +# created_at :datetime not null +# updated_at :datetime not null +# @@ -55,8 +55,8 @@ +# +# id :integer not null, primary key +# content :string - +# count :integer default("0") - +# status :boolean default("0") + +# count :integer default(0) + +# status :boolean default(FALSE) +# created_at :datetime not null +# updated_at :datetime not null +# @@ -76,8 +76,8 @@ +# +# id :integer not null, primary key +# content :string - +# count :integer default("0") - +# status :boolean default("0") + +# count :integer default(0) + +# status :boolean default(FALSE) +# created_at :datetime not null +# updated_at :datetime not null +# diff --git a/spec/integration/rails_6.0.2.1_spec.rb b/spec/integration/rails_6.0.2.1_spec.rb index c73b04291..4622bfe41 100644 --- a/spec/integration/rails_6.0.2.1_spec.rb +++ b/spec/integration/rails_6.0.2.1_spec.rb @@ -34,8 +34,8 @@ +# +# id :integer not null, primary key +# content :string - +# count :integer default("0") - +# status :boolean default("0") + +# count :integer default(0) + +# status :boolean default(FALSE) +# created_at :datetime not null +# updated_at :datetime not null +# @@ -55,8 +55,8 @@ +# +# id :integer not null, primary key +# content :string - +# count :integer default("0") - +# status :boolean default("0") + +# count :integer default(0) + +# status :boolean default(FALSE) +# created_at :datetime not null +# updated_at :datetime not null +# @@ -76,8 +76,8 @@ +# +# id :integer not null, primary key +# content :string - +# count :integer default("0") - +# status :boolean default("0") + +# count :integer default(0) + +# status :boolean default(FALSE) +# created_at :datetime not null +# updated_at :datetime not null +# diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index 1ae7efcde..c3d0069e9 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -351,39 +351,6 @@ def mock_column(name, type, options = {}) end end - context 'when an integer column using ActiveRecord::Enum exists' do - let :columns do - [ - mock_column(:id, :integer), - mock_column(:status, :integer, default: 0) - ] - end - - before :each do - # column_defaults may be overritten when ActiveRecord::Enum is used, e.g: - # class User < ActiveRecord::Base - # enum status: [ :disabled, :enabled ] - # end - allow(klass).to receive(:column_defaults).and_return('id' => nil, 'status' => 'disabled') - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # status :integer default(0), not null - # - EOS - end - - it 'returns schema info with default values' do - is_expected.to eq(expected_result) - end - end - context 'with Globalize gem' do let :translation_klass do double('Post::Translation',