From 7a18fd2ec2ad5c6781df959aa1987d37c568dc8d Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Wed, 22 Jul 2015 17:22:38 +0100 Subject: [PATCH] Return 404 if user not found --- app/controllers/api/v1/users_controller.rb | 2 ++ spec/controllers/api/v1/users_controller_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 2762f2c..9a22225 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -19,5 +19,7 @@ class Api::V1::UsersController < Api::V1::BaseController nickname: @steam.nickname } } + rescue ActiveRecord::RecordNotFound + raise ActionController::RoutingError.new('User Not Found') end end diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index 0fa31b2..73f1740 100644 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -23,6 +23,12 @@ describe Api::V1::UsersController do expect(json['steam']).to have_key("url") expect(json['steam']).to have_key("nickname") end + + it 'returns 404 if user does not exist' do + expect { + get :show, id: -1 + }.to raise_error(ActionController::RoutingError) + end end describe '#index' do