debian-mirror-gitlab/spec/policies/wiki_page_policy_spec.rb

48 lines
1.4 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
require 'spec_helper'
2021-01-29 00:20:46 +05:30
RSpec.describe WikiPagePolicy do
2020-01-01 13:55:28 +05:30
include_context 'ProjectPolicyTable context'
include ProjectHelpers
2022-11-25 23:54:43 +05:30
include UserHelpers
2020-01-01 13:55:28 +05:30
using RSpec::Parameterized::TableSyntax
2022-11-25 23:54:43 +05:30
let(:group) { build(:group, :public) }
let(:project) { build(:project, :wiki_repo, project_level, group: group) }
let(:wiki_page) { build(:wiki_page, container: project) }
2020-01-01 13:55:28 +05:30
2022-11-25 23:54:43 +05:30
shared_context 'with :read_wiki_page policy' do
subject(:policy) { described_class.new(user, wiki_page) }
2020-01-01 13:55:28 +05:30
2022-11-25 23:54:43 +05:30
where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do
permission_table_for_guest_feature_access
end
2020-01-01 13:55:28 +05:30
2022-11-25 23:54:43 +05:30
with_them do
it 'grants the expected permissions' do
enable_admin_mode!(user) if admin_mode
update_feature_access_level(project, feature_access_level)
2020-01-01 13:55:28 +05:30
2022-11-25 23:54:43 +05:30
if expected_count == 1
expect(policy).to be_allowed(:read_wiki_page)
else
expect(policy).to be_disallowed(:read_wiki_page)
end
2020-01-01 13:55:28 +05:30
end
end
end
2022-11-25 23:54:43 +05:30
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
2020-01-01 13:55:28 +05:30
end