Merge branch 'master' into MatchScheduler

This commit is contained in:
Absurdon 2017-10-06 15:35:44 +02:00
commit 548b15489c
2 changed files with 13 additions and 4 deletions

View file

@ -14,7 +14,8 @@ class Api::V1::UsersController < Api::V1::BaseController
end
if @user.nil?
raise ActionController::RoutingError.new("User Not Found")
not_found
return
end
if @user.steamid.present?
@ -44,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
render json: {error: "User not found"}, status: :not_found
end
def steam_profile(user)
SteamCondenser::Community::SteamId.from_steam_id("STEAM_#{user.steamid}")
rescue SteamCondenser::Error

View file

@ -78,11 +78,15 @@ 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)
expect(json["error"]).to eq("User not found")
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)
expect(json["error"]).to eq("User not found")
end
it "queries the steam condenser for an invalid steamid" do