Commit f144cce8 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Update policies unit tests

This commit also makes spec/policies/namespace_policy_spec.rb file
to be compatible with the same file in GitLab EE.
parent a9212e0f
...@@ -56,6 +56,7 @@ describe GroupPolicy do ...@@ -56,6 +56,7 @@ describe GroupPolicy do
expect_disallowed(*developer_permissions) expect_disallowed(*developer_permissions)
expect_disallowed(*master_permissions) expect_disallowed(*master_permissions)
expect_disallowed(*owner_permissions) expect_disallowed(*owner_permissions)
expect_disallowed(:read_namespace)
end end
end end
...@@ -63,7 +64,7 @@ describe GroupPolicy do ...@@ -63,7 +64,7 @@ describe GroupPolicy do
let(:current_user) { guest } let(:current_user) { guest }
it do it do
expect_allowed(:read_group) expect_allowed(:read_group, :read_namespace)
expect_disallowed(*reporter_permissions) expect_disallowed(*reporter_permissions)
expect_disallowed(*developer_permissions) expect_disallowed(*developer_permissions)
expect_disallowed(*master_permissions) expect_disallowed(*master_permissions)
...@@ -75,7 +76,7 @@ describe GroupPolicy do ...@@ -75,7 +76,7 @@ describe GroupPolicy do
let(:current_user) { reporter } let(:current_user) { reporter }
it do it do
expect_allowed(:read_group) expect_allowed(:read_group, :read_namespace)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_disallowed(*developer_permissions) expect_disallowed(*developer_permissions)
expect_disallowed(*master_permissions) expect_disallowed(*master_permissions)
...@@ -87,7 +88,7 @@ describe GroupPolicy do ...@@ -87,7 +88,7 @@ describe GroupPolicy do
let(:current_user) { developer } let(:current_user) { developer }
it do it do
expect_allowed(:read_group) expect_allowed(:read_group, :read_namespace)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_allowed(*developer_permissions) expect_allowed(*developer_permissions)
expect_disallowed(*master_permissions) expect_disallowed(*master_permissions)
...@@ -99,7 +100,7 @@ describe GroupPolicy do ...@@ -99,7 +100,7 @@ describe GroupPolicy do
let(:current_user) { master } let(:current_user) { master }
it do it do
expect_allowed(:read_group) expect_allowed(:read_group, :read_namespace)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_allowed(*developer_permissions) expect_allowed(*developer_permissions)
expect_allowed(*master_permissions) expect_allowed(*master_permissions)
...@@ -113,7 +114,7 @@ describe GroupPolicy do ...@@ -113,7 +114,7 @@ describe GroupPolicy do
it do it do
allow(Group).to receive(:supports_nested_groups?).and_return(true) allow(Group).to receive(:supports_nested_groups?).and_return(true)
expect_allowed(:read_group) expect_allowed(:read_group, :read_namespace)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_allowed(*developer_permissions) expect_allowed(*developer_permissions)
expect_allowed(*master_permissions) expect_allowed(*master_permissions)
...@@ -127,7 +128,7 @@ describe GroupPolicy do ...@@ -127,7 +128,7 @@ describe GroupPolicy do
it do it do
allow(Group).to receive(:supports_nested_groups?).and_return(true) allow(Group).to receive(:supports_nested_groups?).and_return(true)
expect_allowed(:read_group) expect_allowed(:read_group, :read_namespace)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_allowed(*developer_permissions) expect_allowed(*developer_permissions)
expect_allowed(*master_permissions) expect_allowed(*master_permissions)
......
require 'spec_helper' require 'spec_helper'
describe NamespacePolicy do describe NamespacePolicy do
let(:current_user) { create(:user) } let(:user) { create(:user) }
let(:namespace) { current_user.namespace } let(:owner) { create(:user) }
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, owner: owner) }
let(:owner_permissions) { [:create_projects, :admin_namespace, :read_namespace] }
subject { described_class.new(current_user, namespace) } subject { described_class.new(current_user, namespace) }
context "create projects" do context 'with no user' do
context "user namespace" do let(:current_user) { nil }
it { is_expected.to be_allowed(:create_projects) }
end 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 context 'user who has exceeded project limit' do
let(:current_user) { create(:user, projects_limit: 0) } let(:owner) { create(:user, projects_limit: 0) }
it { is_expected.not_to be_allowed(:create_projects) } it { is_expected.not_to be_allowed(:create_projects) }
end end
end end
context 'admin' do
let(:current_user) { admin }
it { is_expected.to be_allowed(*owner_permissions) }
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment