Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Revert #677] Fix column default annotations #768

Merged
merged 4 commits into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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