2019-08-05 16:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ContainerRepositoriesFinder do
|
2019-11-04 10:07:36 -05:00
|
|
|
let_it_be(:reporter) { create(:user) }
|
|
|
|
let_it_be(:guest) { create(:user) }
|
|
|
|
|
2019-08-05 16:00:50 -04:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, group: group) }
|
2019-11-08 04:06:07 -05:00
|
|
|
let!(:project_repository) { create(:container_repository, project: project) }
|
2019-08-05 16:00:50 -04:00
|
|
|
|
2019-11-04 10:07:36 -05:00
|
|
|
before do
|
|
|
|
group.add_reporter(reporter)
|
|
|
|
project.add_reporter(reporter)
|
|
|
|
end
|
|
|
|
|
2019-08-05 16:00:50 -04:00
|
|
|
describe '#execute' do
|
2019-11-04 10:07:36 -05:00
|
|
|
context 'with authorized user' do
|
|
|
|
subject { described_class.new(user: reporter, subject: subject_object).execute }
|
2019-08-05 16:00:50 -04:00
|
|
|
|
2019-11-04 10:07:36 -05:00
|
|
|
context 'when subject_type is group' do
|
|
|
|
let(:subject_object) { group }
|
|
|
|
let(:other_project) { create(:project, group: group) }
|
2019-08-05 16:00:50 -04:00
|
|
|
|
2019-11-04 10:07:36 -05:00
|
|
|
let(:other_repository) do
|
|
|
|
create(:container_repository, name: 'test_repository2', project: other_project)
|
|
|
|
end
|
2019-08-05 16:00:50 -04:00
|
|
|
|
2019-11-04 10:07:36 -05:00
|
|
|
it { is_expected.to match_array([project_repository, other_repository]) }
|
2019-08-05 16:00:50 -04:00
|
|
|
end
|
|
|
|
|
2019-11-04 10:07:36 -05:00
|
|
|
context 'when subject_type is project' do
|
|
|
|
let(:subject_object) { project }
|
2019-08-05 16:00:50 -04:00
|
|
|
|
2019-11-04 10:07:36 -05:00
|
|
|
it { is_expected.to match_array([project_repository]) }
|
|
|
|
end
|
2019-08-05 16:00:50 -04:00
|
|
|
|
2019-11-04 10:07:36 -05:00
|
|
|
context 'with invalid subject_type' do
|
|
|
|
let(:subject_object) { "invalid type" }
|
2019-08-05 16:00:50 -04:00
|
|
|
|
2019-11-04 10:07:36 -05:00
|
|
|
it { expect { subject }.to raise_exception('invalid subject_type') }
|
|
|
|
end
|
2019-08-05 16:00:50 -04:00
|
|
|
end
|
|
|
|
|
2019-11-04 10:07:36 -05:00
|
|
|
context 'with unauthorized user' do
|
|
|
|
subject { described_class.new(user: guest, subject: group).execute }
|
2019-08-05 16:00:50 -04:00
|
|
|
|
2019-11-04 10:07:36 -05:00
|
|
|
it { is_expected.to be nil }
|
2019-08-05 16:00:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|