Skip to content

Commit

Permalink
[Revert #677] Fix column default annotations (#768)
Browse files Browse the repository at this point in the history
It was reported in #762 that column defaults were broken. This reverts changes made in #677 to restore the expected behavior of column defaults. 

For the time being columns with associated enums won't be working.
  • Loading branch information
drwl committed Mar 8, 2020
1 parent f818515 commit 57ec388
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 46 deletions.
2 changes: 1 addition & 1 deletion lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions spec/integration/rails_5.2.4.1_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
+#
Expand All @@ -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
+#
Expand All @@ -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
+#
Expand Down
12 changes: 6 additions & 6 deletions spec/integration/rails_6.0.2.1_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
+#
Expand All @@ -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
+#
Expand All @@ -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
+#
Expand Down
33 changes: 0 additions & 33 deletions spec/lib/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 57ec388

Please sign in to comment.