diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-10 12:09:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-10 12:09:04 +0300 |
commit | c1d4ac251994b4463fb0cfcc263af26ded0d8eac (patch) | |
tree | 94877c6e5f48787924e94b8d1282a73d20e29063 /spec/policies/wiki_page_policy_spec.rb | |
parent | 699bb48edac9e8536ab5eb1ecdf6cfb0ce11d379 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/policies/wiki_page_policy_spec.rb')
-rw-r--r-- | spec/policies/wiki_page_policy_spec.rb | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/spec/policies/wiki_page_policy_spec.rb b/spec/policies/wiki_page_policy_spec.rb index a2fa7f29135..2712026035c 100644 --- a/spec/policies/wiki_page_policy_spec.rb +++ b/spec/policies/wiki_page_policy_spec.rb @@ -5,28 +5,43 @@ require 'spec_helper' RSpec.describe WikiPagePolicy do include_context 'ProjectPolicyTable context' include ProjectHelpers + include UserHelpers using RSpec::Parameterized::TableSyntax - let(:project) { create(:project, :wiki_repo, project_level) } - let(:user) { create_user_from_membership(project, membership) } - let(:wiki_page) { create(:wiki_page, wiki: project.wiki) } + let(:group) { build(:group, :public) } + let(:project) { build(:project, :wiki_repo, project_level, group: group) } + let(:wiki_page) { build(:wiki_page, container: project) } - subject(:policy) { described_class.new(user, wiki_page) } + shared_context 'with :read_wiki_page policy' do + subject(:policy) { described_class.new(user, wiki_page) } - where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do - permission_table_for_guest_feature_access - end + where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do + permission_table_for_guest_feature_access + end - with_them do - it "grants permission" do - enable_admin_mode!(user) if admin_mode - update_feature_access_level(project, feature_access_level) + with_them do + it 'grants the expected permissions' do + enable_admin_mode!(user) if admin_mode + update_feature_access_level(project, feature_access_level) - if expected_count == 1 - expect(policy).to be_allowed(:read_wiki_page) - else - expect(policy).to be_disallowed(:read_wiki_page) + if expected_count == 1 + expect(policy).to be_allowed(:read_wiki_page) + else + expect(policy).to be_disallowed(:read_wiki_page) + end end end end + + context 'when user is a direct project member' do + let(:user) { build_user_from_membership(project, membership) } + + include_context 'with :read_wiki_page policy' + end + + context 'when user is an inherited member from the group' do + let(:user) { build_user_from_membership(group, membership) } + + include_context 'with :read_wiki_page policy' + end end |