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

[ActiveRecord] Fix DB connection issues during assets:precompile #3470

Merged
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/rails_admin/abstract_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def all(adapter = nil)
def new(m)
m = m.constantize unless m.is_a?(Class)
(am = old_new(m)).model && am.adapter ? am : nil
rescue *([LoadError, NameError] + (defined?(ActiveRecord) ? ['ActiveRecord::NoDatabaseError'.constantize] : []))
rescue *([LoadError, NameError] + (defined?(ActiveRecord) ? ['ActiveRecord::NoDatabaseError'.constantize, 'ActiveRecord::ConnectionNotEstablished'.constantize] : []))
puts "[RailsAdmin] Could not load model #{m}, assuming model is non existing. (#{$ERROR_INFO})" unless Rails.env.test?
nil
end
Expand Down
10 changes: 10 additions & 0 deletions spec/rails_admin/abstract_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
expect(RailsAdmin::AbstractModel.new('WithoutTable')).to eq nil
end
end

context 'on ActiveRecord::ConnectionNotEstablished', active_record: true do
before do
expect(WithoutTable).to receive(:table_exists?).and_raise(ActiveRecord::ConnectionNotEstablished)
end

it 'does not raise error and returns nil' do
expect(RailsAdmin::AbstractModel.new('WithoutTable')).to eq nil
end
end
end

describe '#to_s' do
Expand Down