Added team information to usre

This commit is contained in:
Chris Blanchard 2015-08-01 17:05:17 +01:00
parent f9f4485c95
commit cdcf9fedf8
2 changed files with 16 additions and 3 deletions

View file

@ -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')

View file

@ -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