Skip to content

Commit d11f3a0

Browse files
drwlvfonic
authored andcommitted
[Revert ctran#677] Fix column default annotations (ctran#768)
It was reported in ctran#762 that column defaults were broken. This reverts changes made in ctran#677 to restore the expected behavior of column defaults. For the time being columns with associated enums won't be working.
1 parent 30f98b6 commit d11f3a0

File tree

4 files changed

+13
-46
lines changed

4 files changed

+13
-46
lines changed

lib/annotate/annotate_models.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def quote(value)
213213
end
214214

215215
def schema_default(klass, column)
216-
quote(klass.columns.find { |x| x.name.to_s == column.name.to_s }.try(:default))
216+
quote(klass.column_defaults[column.name])
217217
end
218218

219219
def retrieve_indexes_from_table(klass)

spec/integration/rails_5.2.4.1_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
+#
3535
+# id :integer not null, primary key
3636
+# content :string
37-
+# count :integer default("0")
38-
+# status :boolean default("0")
37+
+# count :integer default(0)
38+
+# status :boolean default(FALSE)
3939
+# created_at :datetime not null
4040
+# updated_at :datetime not null
4141
+#
@@ -55,8 +55,8 @@
5555
+#
5656
+# id :integer not null, primary key
5757
+# content :string
58-
+# count :integer default("0")
59-
+# status :boolean default("0")
58+
+# count :integer default(0)
59+
+# status :boolean default(FALSE)
6060
+# created_at :datetime not null
6161
+# updated_at :datetime not null
6262
+#
@@ -76,8 +76,8 @@
7676
+#
7777
+# id :integer not null, primary key
7878
+# content :string
79-
+# count :integer default("0")
80-
+# status :boolean default("0")
79+
+# count :integer default(0)
80+
+# status :boolean default(FALSE)
8181
+# created_at :datetime not null
8282
+# updated_at :datetime not null
8383
+#

spec/integration/rails_6.0.2.1_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
+#
3535
+# id :integer not null, primary key
3636
+# content :string
37-
+# count :integer default("0")
38-
+# status :boolean default("0")
37+
+# count :integer default(0)
38+
+# status :boolean default(FALSE)
3939
+# created_at :datetime not null
4040
+# updated_at :datetime not null
4141
+#
@@ -55,8 +55,8 @@
5555
+#
5656
+# id :integer not null, primary key
5757
+# content :string
58-
+# count :integer default("0")
59-
+# status :boolean default("0")
58+
+# count :integer default(0)
59+
+# status :boolean default(FALSE)
6060
+# created_at :datetime not null
6161
+# updated_at :datetime not null
6262
+#
@@ -76,8 +76,8 @@
7676
+#
7777
+# id :integer not null, primary key
7878
+# content :string
79-
+# count :integer default("0")
80-
+# status :boolean default("0")
79+
+# count :integer default(0)
80+
+# status :boolean default(FALSE)
8181
+# created_at :datetime not null
8282
+# updated_at :datetime not null
8383
+#

spec/lib/annotate/annotate_models_spec.rb

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -351,39 +351,6 @@ def mock_column(name, type, options = {})
351351
end
352352
end
353353

354-
context 'when an integer column using ActiveRecord::Enum exists' do
355-
let :columns do
356-
[
357-
mock_column(:id, :integer),
358-
mock_column(:status, :integer, default: 0)
359-
]
360-
end
361-
362-
before :each do
363-
# column_defaults may be overritten when ActiveRecord::Enum is used, e.g:
364-
# class User < ActiveRecord::Base
365-
# enum status: [ :disabled, :enabled ]
366-
# end
367-
allow(klass).to receive(:column_defaults).and_return('id' => nil, 'status' => 'disabled')
368-
end
369-
370-
let :expected_result do
371-
<<~EOS
372-
# Schema Info
373-
#
374-
# Table name: users
375-
#
376-
# id :integer not null, primary key
377-
# status :integer default(0), not null
378-
#
379-
EOS
380-
end
381-
382-
it 'returns schema info with default values' do
383-
is_expected.to eq(expected_result)
384-
end
385-
end
386-
387354
context 'with Globalize gem' do
388355
let :translation_klass do
389356
double('Post::Translation',

0 commit comments

Comments
 (0)