Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-22 18:09:52 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-22 18:09:52 +0300
commit4136fdda4ca0ec8de51c17efe48425ac35dee590 (patch)
tree79fcdeee7ebc77eb39dd05872b93bdb1a4dcc657 /spec/policies
parentae567e129f79b561404fee0f99082975a8ece087 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/policies')
-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