Commit d1a440e7 authored by Serena Fang's avatar Serena Fang

Add tests for admin current user

parent 545cdd7a
......@@ -4,7 +4,7 @@ module API
module Entities
class UserSafe < Grape::Entity
expose :id, :username
expose :name, unless: ->(user) { user.project_bot? }
expose :name, unless: ->(user) { user.project_bot? && !options[:current_user].admin?}
end
end
end
......@@ -39,8 +39,18 @@ RSpec.describe API::Entities::User do
context 'with project bot user' do
let(:user) { create(:user, :project_bot) }
it 'does not expose project bot user name' do
expect(subject).not_to include(:name)
context 'when the requester is not an admin' do
it 'does not expose project bot user name' do
expect(subject).not_to include(:name)
end
end
context 'when the requester is an admin' do
let(:current_user) { create(:user, :admin) }
it 'exposes project bot user name' do
expect(subject).to include(:name)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment