Skip to content

Commit

Permalink
database_connectivity? should handle not-running database
Browse files Browse the repository at this point in the history
To reproduce, disable your local postgres instance and run
`bundle exec rake test:verify_no_db_access_loading_rails_environment`

Follow up to 76731ae
  • Loading branch information
Fryguy committed Feb 18, 2021
1 parent d5be234 commit 7f4a203
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 1 deletion.
Binary file added db/radar.sqlite3
Binary file not shown.
1 change: 1 addition & 0 deletions lib/tasks/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace :test do
ENV['VERBOSE'] ||= "false"
end

desc "Verifies that the rails enviroment doesn't require DB access"
task :verify_no_db_access_loading_rails_environment do
if Rake::Task['environment'].already_invoked
raise "Failed to verify database access when loading rails because the 'environment' rake task has already been invoked!"
Expand Down
2 changes: 1 addition & 1 deletion lib/vmdb/settings/database_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def resource_queryable?

def database_connectivity?
ActiveRecord::Base.connection && ActiveRecord::Base.connected?
rescue ActiveRecord::NoDatabaseError
rescue ActiveRecord::NoDatabaseError, PG::ConnectionBad
false
end
end
Expand Down

0 comments on commit 7f4a203

Please sign in to comment.