diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-18 21:06:34 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-18 21:06:34 +0000 |
commit | e4c711546c693fff89b0b1c92f1b0dde927e0c84 (patch) | |
tree | 2afa79ebbb72960fd54f1392e0a18031a1d9ee54 /spec | |
parent | b08279013423a66f06f5edde4e067f328fe135bd (diff) | |
download | gitlab-ce-e4c711546c693fff89b0b1c92f1b0dde927e0c84.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
5 files changed, 141 insertions, 66 deletions
diff --git a/spec/controllers/projects/artifacts_controller_spec.rb b/spec/controllers/projects/artifacts_controller_spec.rb index 6ea82785e98..c0b01e573b2 100644 --- a/spec/controllers/projects/artifacts_controller_spec.rb +++ b/spec/controllers/projects/artifacts_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::ArtifactsController do let(:user) { project.owner } set(:project) { create(:project, :repository, :public) } - let(:pipeline) do + set(:pipeline) do create(:ci_pipeline, project: project, sha: project.commit.sha, @@ -14,12 +14,119 @@ describe Projects::ArtifactsController do status: 'success') end - let(:job) { create(:ci_build, :success, :artifacts, pipeline: pipeline) } + let!(:job) { create(:ci_build, :success, :artifacts, pipeline: pipeline) } before do sign_in(user) end + describe 'GET index' do + subject { get :index, params: { namespace_id: project.namespace, project_id: project } } + + context 'when feature flag is on' do + before do + stub_feature_flags(artifacts_management_page: true) + end + + it 'sets the artifacts variable' do + subject + + expect(assigns(:artifacts)).to contain_exactly(*project.job_artifacts) + end + + it 'sets the total size variable' do + subject + + expect(assigns(:total_size)).to eq(project.job_artifacts.total_size) + end + + describe 'pagination' do + before do + stub_const("#{described_class}::MAX_PER_PAGE", 1) + end + + it 'paginates artifacts' do + subject + + expect(assigns(:artifacts)).to contain_exactly(project.job_artifacts.last) + end + end + end + + context 'when feature flag is off' do + before do + stub_feature_flags(artifacts_management_page: false) + end + + it 'renders no content' do + subject + + expect(response).to have_gitlab_http_status(:no_content) + end + + it 'does not set the artifacts variable' do + subject + + expect(assigns(:artifacts)).to eq(nil) + end + + it 'does not set the total size variable' do + subject + + expect(assigns(:total_size)).to eq(nil) + end + end + end + + describe 'DELETE destroy' do + let!(:artifact) { job.job_artifacts.erasable.first } + + subject { delete :destroy, params: { namespace_id: project.namespace, project_id: project, id: artifact } } + + it 'deletes the artifact' do + expect { subject }.to change { Ci::JobArtifact.count }.by(-1) + expect(artifact).not_to exist + end + + it 'redirects to artifacts index page' do + subject + + expect(response).to redirect_to(project_artifacts_path(project)) + end + + it 'sets the notice' do + subject + + expect(flash[:notice]).to eq('Artifact was successfully deleted.') + end + + context 'when artifact deletion fails' do + before do + allow_any_instance_of(Ci::JobArtifact).to receive(:destroy).and_return(false) + end + + it 'redirects to artifacts index page' do + subject + + expect(response).to redirect_to(project_artifacts_path(project)) + end + + it 'sets the notice' do + subject + + expect(flash[:notice]).to eq('Artifact could not be deleted.') + end + end + + context 'when user is not authorized' do + let(:user) { create(:user) } + + it 'does not delete the artifact' do + expect { subject }.not_to change { Ci::JobArtifact.count } + end + end + end + describe 'GET download' do def download_artifact(extra_params = {}) params = { namespace_id: project.namespace, project_id: project, job_id: job }.merge(extra_params) diff --git a/spec/finders/artifacts_finder_spec.rb b/spec/finders/artifacts_finder_spec.rb new file mode 100644 index 00000000000..b956e2c9515 --- /dev/null +++ b/spec/finders/artifacts_finder_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ArtifactsFinder do + let(:project) { create(:project) } + + describe '#execute' do + before do + create(:ci_build, :artifacts, project: project) + end + + subject { described_class.new(project, params).execute } + + context 'with empty params' do + let(:params) { {} } + + it 'returns all artifacts belonging to the project' do + expect(subject).to contain_exactly(*project.job_artifacts) + end + end + + context 'with sort param' do + let(:params) { { sort: 'size_desc' } } + + it 'sorts the artifacts' do + expect(subject).to eq(project.job_artifacts.order_by('size_desc')) + end + end + end +end diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index d3be1e86539..3b43ff3a4e1 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -349,6 +349,7 @@ project: - members_and_requesters - build_trace_section_names - build_trace_chunks +- job_artifacts - root_of_fork_network - fork_network_member - fork_network diff --git a/spec/migrations/migrate_code_owner_approval_status_to_protected_branches_in_batches_spec.rb b/spec/migrations/migrate_code_owner_approval_status_to_protected_branches_in_batches_spec.rb deleted file mode 100644 index 67ac40d4d39..00000000000 --- a/spec/migrations/migrate_code_owner_approval_status_to_protected_branches_in_batches_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require Rails.root.join('db', 'post_migrate', '20190827102026_migrate_code_owner_approval_status_to_protected_branches_in_batches.rb') - -describe MigrateCodeOwnerApprovalStatusToProtectedBranchesInBatches, :migration do - let(:namespaces) { table(:namespaces) } - let(:projects) { table(:projects) } - let(:protected_branches) { table(:protected_branches) } - - let(:namespace) do - namespaces.create!( - path: 'gitlab-instance-administrators', - name: 'GitLab Instance Administrators' - ) - end - - let(:project) do - projects.create!( - namespace_id: namespace.id, - name: 'GitLab Instance Administration' - ) - end - - let!(:protected_branch_1) do - protected_branches.create!( - name: "branch name", - project_id: project.id - ) - end - - describe '#up' do - context "when there's no projects needing approval" do - it "doesn't change any protected branch records" do - expect { migrate! } - .not_to change { ProtectedBranch.where(code_owner_approval_required: true).count } - end - end - - context "when there's a project needing approval" do - let!(:project_needing_approval) do - projects.create!( - namespace_id: namespace.id, - name: 'GitLab Instance Administration', - merge_requests_require_code_owner_approval: true - ) - end - - let!(:protected_branch_2) do - protected_branches.create!( - name: "branch name", - project_id: project_needing_approval.id - ) - end - - it "changes N protected branch records" do - expect { migrate! } - .to change { ProtectedBranch.where(code_owner_approval_required: true).count } - .by(1) - end - end - end -end diff --git a/spec/models/release_spec.rb b/spec/models/release_spec.rb index 8714c67f29d..e7a8d27a036 100644 --- a/spec/models/release_spec.rb +++ b/spec/models/release_spec.rb @@ -20,7 +20,6 @@ RSpec.describe Release do describe 'validation' do it { is_expected.to validate_presence_of(:project) } it { is_expected.to validate_presence_of(:description) } - it { is_expected.to validate_presence_of(:name) } context 'when a release exists in the database without a name' do it 'does not require name' do |