-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2038 from DFE-Digital/fix/check-db-connection-pro…
…perly Check DB connection is available by fetching a record
- Loading branch information
Showing
6 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Ops::DbAvailability | ||
def self.db_available? | ||
return true if User.first && ActiveRecord::Base.connected? | ||
false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "check DB availability" do | ||
describe "db_available?" do | ||
context "when the DB is available" do | ||
it "returns true if there is a user" do | ||
create(:user) | ||
|
||
expect(Ops::DbAvailability.db_available?).to be true | ||
end | ||
end | ||
|
||
context "when the DB is not available" do | ||
before do | ||
allow(ActiveRecord::Base).to receive(:connected?).and_return(false) | ||
end | ||
|
||
it "returns false if there is a user" do | ||
create(:user) | ||
|
||
expect(Ops::DbAvailability.db_available?).to be false | ||
end | ||
|
||
it "returns false if there is NO user and the db is NOT up" do | ||
expect(Ops::DbAvailability.db_available?).to be false | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters