namespace_policy_spec.rb 999 Bytes
Newer Older
1 2 3
require 'spec_helper'

describe NamespacePolicy do
4 5 6 7 8 9
  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] }
10 11 12

  subject { described_class.new(current_user, namespace) }

13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  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) }
29

30 31
    context 'user who has exceeded project limit' do
      let(:owner) { create(:user, projects_limit: 0) }
32 33 34 35

      it { is_expected.not_to be_allowed(:create_projects) }
    end
  end
36 37 38 39 40 41

  context 'admin' do
    let(:current_user) { admin }

    it { is_expected.to be_allowed(*owner_permissions) }
  end
42
end