2017-08-30 14:57:50 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe IssuablePolicy, models: true do
|
2017-12-11 14:21:06 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:policies) { described_class.new(user, issue) }
|
|
|
|
|
2017-08-30 14:57:50 +00:00
|
|
|
describe '#rules' do
|
2018-12-07 15:48:38 +00:00
|
|
|
context 'when user is author of issuable' do
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project, author: user) }
|
|
|
|
let(:policies) { described_class.new(user, merge_request) }
|
|
|
|
|
|
|
|
context 'when user is able to read project' do
|
|
|
|
it 'enables user to read and update issuables' do
|
|
|
|
expect(policies).to be_allowed(:read_issue, :update_issue, :reopen_issue, :read_merge_request, :update_merge_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project is private' do
|
|
|
|
let(:project) { create(:project, :private) }
|
|
|
|
|
|
|
|
context 'when user belongs to the projects team' do
|
|
|
|
it 'enables user to read and update issuables' do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
|
|
|
|
expect(policies).to be_allowed(:read_issue, :update_issue, :reopen_issue, :read_merge_request, :update_merge_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'disallows user from reading and updating issuables from that project' do
|
|
|
|
expect(policies).to be_disallowed(:read_issue, :update_issue, :reopen_issue, :read_merge_request, :update_merge_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-30 14:57:50 +00:00
|
|
|
context 'when discussion is locked for the issuable' do
|
|
|
|
let(:issue) { create(:issue, project: project, discussion_locked: true) }
|
|
|
|
|
|
|
|
context 'when the user is not a project member' do
|
|
|
|
it 'can not create a note' do
|
|
|
|
expect(policies).to be_disallowed(:create_note)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is a project member' do
|
|
|
|
before do
|
2017-09-01 12:03:57 +00:00
|
|
|
project.add_guest(user)
|
2017-08-30 14:57:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can create a note' do
|
|
|
|
expect(policies).to be_allowed(:create_note)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|