From 519f59a9dc14c65b655f5afcc7159bcb0d1b0eaf Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Tue, 21 Jul 2015 14:27:33 +0100 Subject: [PATCH] Added additional data to users json api --- app/controllers/api/v1/users_controller.rb | 6 +++++ .../api/v1/users_controller_spec.rb | 22 ++++++++++++++++++- spec/factories/user.rb | 4 ++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 95128cf..2762f2c 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -8,6 +8,12 @@ class Api::V1::UsersController < Api::V1::BaseController @steam = SteamCondenser::Community::SteamId.from_steam_id("STEAM_#{@user.steamid}") 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: { url: @steam.base_url, nickname: @steam.nickname diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index 7a73530..0fa31b2 100644 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -5,9 +5,29 @@ describe Api::V1::UsersController do request.accept = 'application/json' 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 before do - 10.times { create(:user_with_team) } + 5.times { create(:user_with_team) } end it 'returns all users and associated teams' do diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 9b15973..74942ac 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -20,6 +20,10 @@ FactoryGirl.define do end end + trait :chris do + steamid "0:1:58097444" + end + factory :user_with_team do after(:create) do |user| create(:team, founder: user)