summaryrefslogtreecommitdiff
path: root/spec/policies/timelog_policy_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
commit36a59d088eca61b834191dacea009677a96c052f (patch)
treee4f33972dab5d8ef79e3944a9f403035fceea43f /spec/policies/timelog_policy_spec.rb
parenta1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff)
downloadgitlab-ce-36a59d088eca61b834191dacea009677a96c052f.tar.gz
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/policies/timelog_policy_spec.rb')
-rw-r--r--spec/policies/timelog_policy_spec.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/policies/timelog_policy_spec.rb b/spec/policies/timelog_policy_spec.rb
new file mode 100644
index 00000000000..97e61cfe5ce
--- /dev/null
+++ b/spec/policies/timelog_policy_spec.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe TimelogPolicy, models: true do
+ let_it_be(:author) { create(:user) }
+ let_it_be(:project) { create(:project, :public) }
+ let_it_be(:issue) { create(:issue, project: project) }
+ let_it_be(:timelog) { create(:timelog, user: author, issue: issue, time_spent: 1800)}
+
+ let(:user) { nil }
+ let(:policy) { described_class.new(user, timelog) }
+
+ describe '#rules' do
+ context 'when user is anonymus' do
+ it 'prevents adimistration of timelog' do
+ expect(policy).to be_disallowed(:admin_timelog)
+ end
+ end
+
+ context 'when user is the author of the timelog' do
+ let(:user) { author }
+
+ it 'allows adimistration of timelog' do
+ expect(policy).to be_allowed(:admin_timelog)
+ end
+ end
+
+ context 'when user is not the author of the timelog but maintainer of the project' do
+ let(:user) { create(:user) }
+
+ before do
+ project.add_maintainer(user)
+ end
+
+ it 'allows adimistration of timelog' do
+ expect(policy).to be_allowed(:admin_timelog)
+ end
+ end
+
+ context 'when user is not the timelog\'s author, not a maintainer but an administrator', :enable_admin_mode do
+ let(:user) { create(:user, :admin) }
+
+ it 'allows adimistration of timelog' do
+ expect(policy).to be_allowed(:admin_timelog)
+ end
+ end
+
+ context 'when user is not the author of the timelog nor a maintainer of the project nor an administrator' do
+ let(:user) { create(:user) }
+
+ it 'prevents adimistration of timelog' do
+ expect(policy).to be_disallowed(:admin_timelog)
+ end
+ end
+ end
+end