mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-11-15 09:21:25 +00:00
Invalid steam ids on the users API now returns null for steam attributes
This commit is contained in:
parent
80c733143b
commit
c7a81d8e75
3 changed files with 24 additions and 5 deletions
|
@ -5,7 +5,7 @@ class Api::V1::UsersController < Api::V1::BaseController
|
|||
|
||||
def show
|
||||
@user = User.find(params[:id])
|
||||
@steam = SteamCondenser::Community::SteamId.from_steam_id("STEAM_#{@user.steamid}")
|
||||
@steam = steam_profile @user
|
||||
|
||||
render json: {
|
||||
id: @user.id,
|
||||
|
@ -15,8 +15,8 @@ class Api::V1::UsersController < Api::V1::BaseController
|
|||
avatar: @user.profile.avatar.url,
|
||||
admin: @user.admin?,
|
||||
steam: {
|
||||
url: @steam.base_url,
|
||||
nickname: @steam.nickname
|
||||
url: @steam.nil? ? nil : @steam.base_url,
|
||||
nickname: @steam.nil? ? nil : @steam.nickname
|
||||
},
|
||||
bans: {
|
||||
gather: @user.banned?(Ban::TYPE_GATHER).present?,
|
||||
|
@ -28,4 +28,12 @@ class Api::V1::UsersController < Api::V1::BaseController
|
|||
rescue ActiveRecord::RecordNotFound
|
||||
raise ActionController::RoutingError.new('User Not Found')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def steam_profile user
|
||||
SteamCondenser::Community::SteamId.from_steam_id("STEAM_#{user.steamid}")
|
||||
rescue SteamCondenser::Error => e
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,6 +28,17 @@ describe Api::V1::UsersController do
|
|||
expect(json['team']).to be_nil
|
||||
end
|
||||
|
||||
it 'returns data for users with invalid steam ids' do
|
||||
@user.steamid = '0:0:000'
|
||||
@user.save!
|
||||
|
||||
get :show, id: @user.id
|
||||
|
||||
expect(response).to be_success
|
||||
expect(json['steam']['url']).to be_nil
|
||||
expect(json['steam']['nickname']).to be_nil
|
||||
end
|
||||
|
||||
it 'returns 404 if user does not exist' do
|
||||
expect {
|
||||
get :show, id: -1
|
||||
|
|
|
@ -23,8 +23,8 @@ describe Api::V1::UsersCollection do
|
|||
expect(collection.execute_query.size).to eq(3)
|
||||
end
|
||||
|
||||
it 'returns 5 columns' do
|
||||
expect(collection.execute_query.first.size).to eq(5)
|
||||
it 'returns 6 columns' do
|
||||
expect(collection.execute_query.first.size).to eq(6)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue