debian-mirror-gitlab/spec/finders/container_repositories_finder_spec.rb

74 lines
2.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe ContainerRepositoriesFinder do
2019-12-26 22:10:19 +05:30
let_it_be(:reporter) { create(:user) }
let_it_be(:guest) { create(:user) }
2020-05-24 23:13:21 +05:30
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:project_repository) { create(:container_repository, name: 'my_image', project: project) }
let(:params) { {} }
2019-12-26 22:10:19 +05:30
before do
group.add_reporter(reporter)
project.add_reporter(reporter)
end
2019-10-12 21:52:04 +05:30
2020-05-24 23:13:21 +05:30
shared_examples 'with name search' do
let_it_be(:not_searched_repository) do
create(:container_repository, name: 'foo_bar_baz', project: project)
end
%w[my_image my_imag _image _imag].each do |name|
context "with name set to #{name}" do
let(:params) { { name: name } }
it { is_expected.to contain_exactly(project_repository)}
it { is_expected.not_to include(not_searched_repository)}
end
end
end
2019-10-12 21:52:04 +05:30
describe '#execute' do
2019-12-26 22:10:19 +05:30
context 'with authorized user' do
2020-05-24 23:13:21 +05:30
subject { described_class.new(user: reporter, subject: subject_object, params: params).execute }
2019-10-12 21:52:04 +05:30
2019-12-26 22:10:19 +05:30
context 'when subject_type is group' do
let(:subject_object) { group }
let(:other_project) { create(:project, group: group) }
2019-10-12 21:52:04 +05:30
2019-12-26 22:10:19 +05:30
let(:other_repository) do
create(:container_repository, name: 'test_repository2', project: other_project)
end
2019-10-12 21:52:04 +05:30
2019-12-26 22:10:19 +05:30
it { is_expected.to match_array([project_repository, other_repository]) }
2020-05-24 23:13:21 +05:30
it_behaves_like 'with name search'
2019-10-12 21:52:04 +05:30
end
2019-12-26 22:10:19 +05:30
context 'when subject_type is project' do
let(:subject_object) { project }
2019-10-12 21:52:04 +05:30
2019-12-26 22:10:19 +05:30
it { is_expected.to match_array([project_repository]) }
2020-05-24 23:13:21 +05:30
it_behaves_like 'with name search'
2019-12-26 22:10:19 +05:30
end
2019-10-12 21:52:04 +05:30
2019-12-26 22:10:19 +05:30
context 'with invalid subject_type' do
let(:subject_object) { "invalid type" }
2019-10-12 21:52:04 +05:30
2019-12-26 22:10:19 +05:30
it { expect { subject }.to raise_exception('invalid subject_type') }
end
2019-10-12 21:52:04 +05:30
end
2019-12-26 22:10:19 +05:30
context 'with unauthorized user' do
subject { described_class.new(user: guest, subject: group).execute }
2019-10-12 21:52:04 +05:30
2019-12-26 22:10:19 +05:30
it { is_expected.to be nil }
2019-10-12 21:52:04 +05:30
end
end
end