2017-09-29 07:14:39 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe NamespacePolicy do
|
2017-11-27 15:26:50 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let(:namespace) { create(:namespace, owner: owner) }
|
|
|
|
|
|
|
|
let(:owner_permissions) { [:create_projects, :admin_namespace, :read_namespace] }
|
2017-09-29 07:14:39 -04:00
|
|
|
|
|
|
|
subject { described_class.new(current_user, namespace) }
|
|
|
|
|
2017-11-27 15:26:50 -05:00
|
|
|
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) }
|
2017-09-29 07:14:39 -04:00
|
|
|
|
2017-11-27 15:26:50 -05:00
|
|
|
context 'user who has exceeded project limit' do
|
|
|
|
let(:owner) { create(:user, projects_limit: 0) }
|
2017-09-29 07:14:39 -04:00
|
|
|
|
2019-03-26 04:22:46 -04:00
|
|
|
it { is_expected.to be_disallowed(:create_projects) }
|
2017-09-29 07:14:39 -04:00
|
|
|
end
|
|
|
|
end
|
2017-11-27 15:26:50 -05:00
|
|
|
|
|
|
|
context 'admin' do
|
|
|
|
let(:current_user) { admin }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(*owner_permissions) }
|
|
|
|
end
|
2017-09-29 07:14:39 -04:00
|
|
|
end
|