diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/policies/work_item_policy_spec.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/policies/work_item_policy_spec.rb')
-rw-r--r-- | spec/policies/work_item_policy_spec.rb | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/spec/policies/work_item_policy_spec.rb b/spec/policies/work_item_policy_spec.rb index 08a22a95540..b19f7d2557d 100644 --- a/spec/policies/work_item_policy_spec.rb +++ b/spec/policies/work_item_policy_spec.rb @@ -3,11 +3,13 @@ require 'spec_helper' RSpec.describe WorkItemPolicy do - let_it_be(:project) { create(:project) } - let_it_be(:public_project) { create(:project, :public) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } + let_it_be(:public_project) { create(:project, :public, group: group) } let_it_be(:guest) { create(:user).tap { |user| project.add_guest(user) } } let_it_be(:guest_author) { create(:user).tap { |user| project.add_guest(user) } } let_it_be(:reporter) { create(:user).tap { |user| project.add_reporter(user) } } + let_it_be(:group_reporter) { create(:user).tap { |user| group.add_reporter(user) } } let_it_be(:non_member_user) { create(:user) } let_it_be(:work_item) { create(:work_item, project: project) } let_it_be(:authored_work_item) { create(:work_item, project: project, author: guest_author) } @@ -81,7 +83,9 @@ RSpec.describe WorkItemPolicy do let(:work_item_subject) { work_item } let(:current_user) { reporter } - it { is_expected.to be_disallowed(:delete_work_item) } + context 'when the user is not the author of the work item' do + it { is_expected.to be_disallowed(:delete_work_item) } + end context 'when guest authored the work item' do let(:work_item_subject) { authored_work_item } @@ -90,5 +94,35 @@ RSpec.describe WorkItemPolicy do it { is_expected.to be_allowed(:delete_work_item) } end end + + context 'when user is member of the project\'s group' do + let(:current_user) { group_reporter } + + context 'when the user is not the author of the work item' do + it { is_expected.to be_disallowed(:delete_work_item) } + end + + context 'when user authored the work item' do + let(:work_item_subject) { create(:work_item, project: project, author: current_user) } + + it { is_expected.to be_allowed(:delete_work_item) } + end + end + + context 'when user is not a member of the project' do + let(:current_user) { non_member_user } + + context 'when the user authored the work item' do + let(:work_item_subject) { create(:work_item, project: public_project, author: current_user) } + + it { is_expected.to be_disallowed(:delete_work_item) } + end + + context 'when the user is not the author of the work item' do + let(:work_item_subject) { public_work_item } + + it { is_expected.to be_disallowed(:delete_work_item) } + end + end end end |