Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SomeController < ApplicationController
- def some_action
- Model.find(params[:id])
- rescue ActiveRecord::RecordNotFound
- redirect_to {:controller => some_controller, :action_some_action}
- end
- end
- # Basic
- it 'catches RecordNotFound error' do
- error = ActiveRecord::RecordNotFound.new
- expect {
- Model.should_receive(:find).and_raise(error)
- post :show, { :id => 2 }
- }.to_not raise_error
- end
- # Better: Test for the actions expected when rescuing the error
- it 'redirects to some_controller#some_action' do
- error = ActiveRecord::RecordNotFound.new
- Model.should_receive(:find).and_raise(error)
- post :show, { :id => 'something that does not exist' }
- response.should redirect_to('/wherever-it-should')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement