mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-14 13:51:26 +00:00
Added additional data to users json api
This commit is contained in:
parent
b24f808c48
commit
519f59a9dc
3 changed files with 31 additions and 1 deletions
|
@ -8,6 +8,12 @@ class Api::V1::UsersController < Api::V1::BaseController
|
||||||
@steam = SteamCondenser::Community::SteamId.from_steam_id("STEAM_#{@user.steamid}")
|
@steam = SteamCondenser::Community::SteamId.from_steam_id("STEAM_#{@user.steamid}")
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
|
id: @user.id,
|
||||||
|
username: @user.username,
|
||||||
|
country: @user.country,
|
||||||
|
time_zone: @user.time_zone,
|
||||||
|
avatar: @user.profile.avatar.url,
|
||||||
|
admin: @user.admin?,
|
||||||
steam: {
|
steam: {
|
||||||
url: @steam.base_url,
|
url: @steam.base_url,
|
||||||
nickname: @steam.nickname
|
nickname: @steam.nickname
|
||||||
|
|
|
@ -5,9 +5,29 @@ describe Api::V1::UsersController do
|
||||||
request.accept = 'application/json'
|
request.accept = 'application/json'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#show' do
|
||||||
|
before do
|
||||||
|
@user = create :user_with_team, :chris
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns user data' do
|
||||||
|
get :show, id: @user.id
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
expect(json['id']).to eq(@user.id)
|
||||||
|
expect(json['username']).to eq(@user.username)
|
||||||
|
expect(json['country']).to eq(@user.country)
|
||||||
|
expect(json['time_zone']).to eq(@user.time_zone)
|
||||||
|
expect(json['admin']).to eq(@user.admin?)
|
||||||
|
expect(json).to have_key("steam")
|
||||||
|
expect(json['steam']).to have_key("url")
|
||||||
|
expect(json['steam']).to have_key("nickname")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#index' do
|
describe '#index' do
|
||||||
before do
|
before do
|
||||||
10.times { create(:user_with_team) }
|
5.times { create(:user_with_team) }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns all users and associated teams' do
|
it 'returns all users and associated teams' do
|
||||||
|
|
|
@ -20,6 +20,10 @@ FactoryGirl.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :chris do
|
||||||
|
steamid "0:1:58097444"
|
||||||
|
end
|
||||||
|
|
||||||
factory :user_with_team do
|
factory :user_with_team do
|
||||||
after(:create) do |user|
|
after(:create) do |user|
|
||||||
create(:team, founder: user)
|
create(:team, founder: user)
|
||||||
|
|
Loading…
Reference in a new issue