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

37 lines
1 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 BlobPolicy do
2020-01-01 13:55:28 +05:30
include_context 'ProjectPolicyTable context'
include ProjectHelpers
2022-03-02 08:16:31 +05:30
let_it_be_with_reload(:project) { create(:project, :repository) }
2020-01-01 13:55:28 +05:30
let(:user) { create_user_from_membership(project, membership) }
let(:blob) { project.repository.blob_at(SeedRepo::FirstCommit::ID, 'README.md') }
subject(:policy) { described_class.new(user, blob) }
2021-01-29 00:20:46 +05:30
where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do
2020-01-01 13:55:28 +05:30
permission_table_for_guest_feature_access_and_non_private_project_only
end
with_them do
2022-03-02 08:16:31 +05:30
it 'grants permission' do
2021-01-29 00:20:46 +05:30
enable_admin_mode!(user) if admin_mode
2022-07-23 23:45:48 +05:30
update_feature_access_level(
project,
feature_access_level,
visibility_level: Gitlab::VisibilityLevel.level_value(project_level.to_s)
)
2020-01-01 13:55:28 +05:30
if expected_count == 1
expect(policy).to be_allowed(:read_blob)
else
expect(policy).to be_disallowed(:read_blob)
end
end
end
end