From d6e317b6f0dd49415f23ceabb2d867ba5f9d845a Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 1 Aug 2015 17:05:17 +0100 Subject: [PATCH] Added team information to usre --- app/controllers/api/v1/users_controller.rb | 3 ++- spec/controllers/api/v1/users_controller_spec.rb | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index af2f5ff..ea0f56b 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -22,7 +22,8 @@ class Api::V1::UsersController < Api::V1::BaseController gather: @user.banned?(Ban::TYPE_GATHER).present?, mute: @user.banned?(Ban::TYPE_MUTE).present?, site: @user.banned?(Ban::TYPE_SITE).present? - } + }, + team: @user.team.present? ? { id: @user.team.id, name: @user.team.name } : nil } rescue ActiveRecord::RecordNotFound raise ActionController::RoutingError.new('User Not Found') diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index 4cc19e6..534b939 100644 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -6,8 +6,8 @@ describe Api::V1::UsersController do end describe '#show' do - before do - @user = create :user_with_team, :chris + before(:each) do + @user = create :user, :chris end it 'returns user data' do @@ -22,6 +22,10 @@ describe Api::V1::UsersController do expect(json).to have_key("steam") expect(json['steam']).to have_key("url") expect(json['steam']).to have_key("nickname") + expect(json['bans']['mute']).to eq(false) + expect(json['bans']['gather']).to eq(false) + expect(json['bans']['site']).to eq(false) + expect(json['team']).to be_nil end it 'returns 404 if user does not exist' do @@ -48,6 +52,14 @@ describe Api::V1::UsersController do expect(response).to be_success expect(json['bans']['site']).to eq(true) end + it 'returns team information' do + @user.destroy + @user_with_team = create :user_with_team, :chris + get :show, id: @user_with_team.id + expect(response).to be_success + expect(json['team']['id']).to eq(@user_with_team.team.id) + expect(json['team']['name']).to eq(@user_with_team.team.name) + end end describe '#index' do