diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-04 18:07:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-04 18:07:36 +0300 |
commit | aa542224bb345acf0cb9a1a606f0a802c16b0336 (patch) | |
tree | 496540a29aec55c6faeec7b0140824547046ae6c /spec/finders/container_repositories_finder_spec.rb | |
parent | 2494b608a460c46c759ad84bb29e6cc3447499a1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders/container_repositories_finder_spec.rb')
-rw-r--r-- | spec/finders/container_repositories_finder_spec.rb | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/spec/finders/container_repositories_finder_spec.rb b/spec/finders/container_repositories_finder_spec.rb index deec62d6598..43b82faa9a3 100644 --- a/spec/finders/container_repositories_finder_spec.rb +++ b/spec/finders/container_repositories_finder_spec.rb @@ -3,42 +3,50 @@ require 'spec_helper' describe ContainerRepositoriesFinder do + let_it_be(:reporter) { create(:user) } + let_it_be(:guest) { create(:user) } + let(:group) { create(:group) } let(:project) { create(:project, group: group) } let(:project_repository) { create(:container_repository, project: project) } + before do + group.add_reporter(reporter) + project.add_reporter(reporter) + end + describe '#execute' do - let(:id) { nil } + context 'with authorized user' do + subject { described_class.new(user: reporter, subject: subject_object).execute } - subject { described_class.new(id: id, container_type: container_type).execute } + context 'when subject_type is group' do + let(:subject_object) { group } + let(:other_project) { create(:project, group: group) } - context 'when container_type is group' do - let(:other_project) { create(:project, group: group) } + let(:other_repository) do + create(:container_repository, name: 'test_repository2', project: other_project) + end - let(:other_repository) do - create(:container_repository, name: 'test_repository2', project: other_project) + it { is_expected.to match_array([project_repository, other_repository]) } end - let(:container_type) { :group } - let(:id) { group.id } + context 'when subject_type is project' do + let(:subject_object) { project } - it { is_expected.to match_array([project_repository, other_repository]) } - end + it { is_expected.to match_array([project_repository]) } + end - context 'when container_type is project' do - let(:container_type) { :project } - let(:id) { project.id } + context 'with invalid subject_type' do + let(:subject_object) { "invalid type" } - it { is_expected.to match_array([project_repository]) } + it { expect { subject }.to raise_exception('invalid subject_type') } + end end - context 'with invalid id' do - let(:container_type) { :project } - let(:id) { 123456789 } + context 'with unauthorized user' do + subject { described_class.new(user: guest, subject: group).execute } - it 'raises an error' do - expect { subject.execute }.to raise_error(ActiveRecord::RecordNotFound) - end + it { is_expected.to be nil } end end end |