404 bad user API requests & spec

This commit is contained in:
Prommah 2017-09-30 04:07:40 +02:00 committed by Absurdon
parent 6b5cafcbf0
commit 56087b09f3
2 changed files with 10 additions and 4 deletions

View file

@ -14,7 +14,7 @@ class Api::V1::UsersController < Api::V1::BaseController
end
if @user.nil?
render json: nil, status: :not_found
not_found
return
end
@ -45,11 +45,15 @@ class Api::V1::UsersController < Api::V1::BaseController
team: @user.team.present? ? { id: @user.team.id, name: @user.team.name } : nil
}
rescue ActiveRecord::RecordNotFound
raise ActionController::RoutingError.new("User Not Found")
not_found
end
private
def not_found
head :not_found
end
def steam_profile(user)
SteamCondenser::Community::SteamId.from_steam_id("STEAM_#{user.steamid}")
rescue SteamCondenser::Error

View file

@ -78,11 +78,13 @@ describe Api::V1::UsersController do
end
it "returns 404 if user does not exist" do
expect { get :show, id: -1 }.to raise_error(ActionController::RoutingError)
get :show, id: -1
expect(response.status).to eq(404)
end
it "returns 404 if user does not exist by steamid" do
expect { get :show, id: -1, format: "steamid" }.to raise_error(ActionController::RoutingError)
get :show, id: -1, format: "steamid"
expect(response.status).to eq(404)
end
it "queries the steam condenser for an invalid steamid" do