2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe NamespacePolicy do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let(:namespace) { create(:namespace, owner: owner) }
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
let(:owner_permissions) { [:owner_access, :create_projects, :admin_namespace, :read_namespace, :read_statistics, :transfer_projects, :create_package_settings, :read_package_settings] }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
subject { described_class.new(current_user, namespace) }
|
|
|
|
|
|
|
|
context 'with no user' do
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to be_banned }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'regular user' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*owner_permissions) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'owner' do
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(*owner_permissions) }
|
|
|
|
|
|
|
|
context 'user who has exceeded project limit' do
|
|
|
|
let(:owner) { create(:user, projects_limit: 0) }
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it { is_expected.to be_disallowed(:create_projects) }
|
2019-10-31 01:37:42 +05:30
|
|
|
it { is_expected.to be_disallowed(:transfer_projects) }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'admin' do
|
|
|
|
let(:current_user) { admin }
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
context 'when admin mode is enabled', :enable_admin_mode do
|
|
|
|
it { is_expected.to be_allowed(*owner_permissions) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin mode is disabled' do
|
|
|
|
it { is_expected.to be_disallowed(*owner_permissions) }
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
describe 'create_jira_connect_subscription' do
|
|
|
|
context 'admin' do
|
|
|
|
let(:current_user) { build_stubbed(:admin) }
|
|
|
|
|
|
|
|
context 'when admin mode enabled', :enable_admin_mode do
|
|
|
|
it { is_expected.to be_allowed(:create_jira_connect_subscription) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin mode disabled' do
|
|
|
|
it { is_expected.to be_disallowed(:create_jira_connect_subscription) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'owner' do
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:create_jira_connect_subscription) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'other user' do
|
|
|
|
let(:current_user) { build_stubbed(:user) }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:create_jira_connect_subscription) }
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|