diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-26 03:06:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-26 03:06:28 +0300 |
commit | 9615736987b94a783845354ba881008e49d39238 (patch) | |
tree | 0620a1d06e44df92fa936b7a86e57d282f690181 /spec/finders | |
parent | eb7390edf3afd52174b786fff1e06d5ffae0cec5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders')
-rw-r--r-- | spec/finders/jobs_finder_spec.rb | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/spec/finders/jobs_finder_spec.rb b/spec/finders/jobs_finder_spec.rb new file mode 100644 index 00000000000..675d170b90e --- /dev/null +++ b/spec/finders/jobs_finder_spec.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe JobsFinder, '#execute' do + set(:user) { create(:user) } + set(:admin) { create(:user, :admin) } + set(:project) { create(:project, :private, public_builds: false) } + set(:pipeline) { create(:ci_pipeline, project: project) } + set(:job_1) { create(:ci_build) } + set(:job_2) { create(:ci_build, :running) } + set(:job_3) { create(:ci_build, :success, pipeline: pipeline) } + + let(:params) { {} } + + context 'no project' do + subject { described_class.new(current_user: admin, params: params).execute } + + it 'returns all jobs' do + expect(subject).to match_array([job_1, job_2, job_3]) + end + + context 'non admin user' do + let(:admin) { user } + + it 'returns no jobs' do + expect(subject).to be_empty + end + end + + context 'without user' do + let(:admin) { nil } + + it 'returns no jobs' do + expect(subject).to be_empty + end + end + + context 'scope is present' do + let(:jobs) { [job_1, job_2, job_3] } + + where(:scope, :index) do + [ + ['pending', 0], + ['running', 1], + ['finished', 2] + ] + end + + with_them do + let(:params) { { scope: scope } } + + it { expect(subject).to match_array([jobs[index]]) } + end + end + end + + context 'a project is present' do + subject { described_class.new(current_user: user, project: project, params: params).execute } + + context 'user has access to the project' do + before do + project.add_maintainer(user) + end + + it 'returns jobs for the specified project' do + expect(subject).to match_array([job_3]) + end + end + + context 'user has no access to project builds' do + before do + project.add_guest(user) + end + + it 'returns no jobs' do + expect(subject).to be_empty + end + end + + context 'without user' do + let(:user) { nil } + + it 'returns no jobs' do + expect(subject).to be_empty + end + end + end +end |