1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProtectedBranch::CacheKey, feature_category: :source_code_management do
subject(:cache_key) { described_class.new(entity) }
let_it_be(:project) { create(:project) }
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:user) }
describe '#to_s' do
subject { cache_key.to_s }
context 'with entity project' do
let(:entity) { project }
it 'returns a scoped key' do
is_expected.to eq "cache:gitlab:protected_branch:project:#{project.id}"
end
context 'when a project presenter is provided' do
let(:entity) { ProjectPresenter.new(project) }
it 'returns the same key as a project' do
is_expected.to eq "cache:gitlab:protected_branch:project:#{project.id}"
end
end
end
context 'with entity group' do
let(:entity) { group }
it 'returns a scoped key' do
is_expected.to eq "cache:gitlab:protected_branch:group:#{group.id}"
end
end
context 'with an unsupported entity' do
let(:entity) { user }
it 'returns a scoped key' do
is_expected.to eq "cache:gitlab:protected_branch:user:#{user.id}"
end
end
end
end
|