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 11class PingController < ApplicationController
22 def index
3- raise PG :: Error unless ActiveRecord ::Base . connectable?
3+ ActiveRecord ::Base . connectable!
44
55 render :plain => 'pong' , :status => 200
66 end
77
88 private def error_handler ( e )
99 message =
1010 case e
11- when PG :: Error
11+ when * ActiveRecord :: Base :: CONNECTIVITY_ERRORS
1212 "Unable to connect to the database"
1313 else
1414 "Unknown"
Original file line number Diff line number Diff line change 99 end
1010
1111 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 )
1313
1414 get :index
1515
1616 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 )" )
1818 end
1919
2020 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 )
2222
2323 get :index
2424
You can’t perform that action at this time.
0 commit comments