Add specs for TriggerVariableEntity

This commit is contained in:
Matija Čupić 2018-12-07 17:01:31 +01:00
parent c2f72ad8a2
commit c1a098c78b
No known key found for this signature in database
GPG key ID: 4BAF84FFACD2E5DE
2 changed files with 50 additions and 1 deletions

View file

@ -4,5 +4,5 @@ class TriggerVariableEntity < Grape::Entity
include RequestAwareEntity
expose :key, :public
expose :value, if: ->(_, _) { request.project.team.maintainer?(request.current_user) }
expose :value, if: ->(_, _) { can?(request.current_user, :admin_build, request.project) }
end

View file

@ -0,0 +1,49 @@
require 'spec_helper'
describe TriggerVariableEntity do
let(:project) { create(:project) }
let(:request) { double('request') }
let(:user) { create(:user) }
let(:variable) { { key: 'TEST_KEY', value: 'TEST_VALUE' } }
subject { described_class.new(variable, request: request).as_json }
before do
allow(request).to receive(:current_user).and_return(user)
allow(request).to receive(:project).and_return(project)
end
it 'exposes the variable key' do
expect(subject).to include(:key)
end
context 'when user has access to the value' do
context 'when user is maintainer' do
before do
project.team.add_maintainer(user)
end
it 'exposes the variable value' do
expect(subject).to include(:value)
end
end
context 'when user is owner' do
let(:user) { project.owner }
it 'exposes the variable value' do
expect(subject).to include(:value)
end
end
end
context 'when user does not have access to the value' do
before do
project.team.add_developer(user)
end
it 'does not expose the variable value' do
expect(subject).not_to include(:value)
end
end
end