File tree Expand file tree Collapse file tree 2 files changed +5
-5
lines changed Expand file tree Collapse file tree 2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change 1
1
class PingController < ApplicationController
2
2
def index
3
- raise PG :: Error unless ActiveRecord ::Base . connectable?
3
+ ActiveRecord ::Base . connectable!
4
4
5
5
render :plain => 'pong' , :status => 200
6
6
end
7
7
8
8
private def error_handler ( e )
9
9
message =
10
10
case e
11
- when PG :: Error
11
+ when * ActiveRecord :: Base :: CONNECTIVITY_ERRORS
12
12
"Unable to connect to the database"
13
13
else
14
14
"Unknown"
Original file line number Diff line number Diff line change 9
9
end
10
10
11
11
it 'fails gracefully with database errors' do
12
- expect ( ActiveRecord ::Base ) . to receive ( :connectable? ) . and_return ( false )
12
+ expect ( ActiveRecord ::Base ) . to receive ( :connectable! ) . and_raise ( PG :: ConnectionBad )
13
13
14
14
get :index
15
15
16
16
expect ( response . status ) . to eq ( 500 )
17
- expect ( response . body ) . to eq ( "ERROR: Unable to connect to the database (PG::Error )" )
17
+ expect ( response . body ) . to eq ( "ERROR: Unable to connect to the database (PG::ConnectionBad )" )
18
18
end
19
19
20
20
it 'fails gracefully with non-database errors' do
21
- expect ( ActiveRecord ::Base ) . to receive ( :connectable? ) . and_raise ( RuntimeError )
21
+ expect ( ActiveRecord ::Base ) . to receive ( :connectable! ) . and_raise ( RuntimeError )
22
22
23
23
get :index
24
24
You can’t perform that action at this time.
0 commit comments