diff options
Diffstat (limited to 'spec/controllers')
4 files changed, 10 insertions, 165 deletions
diff --git a/spec/controllers/dashboard/todos_controller_spec.rb b/spec/controllers/dashboard/todos_controller_spec.rb index 4ce445fe41a..c5af04f72ee 100644 --- a/spec/controllers/dashboard/todos_controller_spec.rb +++ b/spec/controllers/dashboard/todos_controller_spec.rb @@ -131,7 +131,7 @@ describe Dashboard::TodosController do expect(todo.reload).to be_pending expect(response).to have_gitlab_http_status(200) - expect(json_response).to eq({ "count" => 1, "done_count" => 0 }) + expect(json_response).to eq({ "count" => "1", "done_count" => "0" }) end end @@ -145,7 +145,7 @@ describe Dashboard::TodosController do expect(todo.reload).to be_pending end expect(response).to have_gitlab_http_status(200) - expect(json_response).to eq({ 'count' => 2, 'done_count' => 0 }) + expect(json_response).to eq({ 'count' => '2', 'done_count' => '0' }) end end end diff --git a/spec/controllers/projects/artifacts_controller_spec.rb b/spec/controllers/projects/artifacts_controller_spec.rb index c0b01e573b2..6ea82785e98 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) } - set(:pipeline) do + let(:pipeline) do create(:ci_pipeline, project: project, sha: project.commit.sha, @@ -14,119 +14,12 @@ 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/controllers/projects/registry/tags_controller_spec.rb b/spec/controllers/projects/registry/tags_controller_spec.rb index 8da0d217e9e..c6e063d8229 100644 --- a/spec/controllers/projects/registry/tags_controller_spec.rb +++ b/spec/controllers/projects/registry/tags_controller_spec.rb @@ -10,8 +10,6 @@ describe Projects::Registry::TagsController do create(:container_repository, name: 'image', project: project) end - let(:service) { double('service') } - before do sign_in(user) stub_container_registry_config(enabled: true) @@ -86,17 +84,17 @@ describe Projects::Registry::TagsController do context 'when there is matching tag present' do before do - stub_container_registry_tags(repository: repository.path, tags: %w[rc1], with_manifest: true) + stub_container_registry_tags(repository: repository.path, tags: %w[rc1 test.]) end it 'makes it possible to delete regular tag' do - expect_delete_tags(%w[rc1]) + expect_any_instance_of(ContainerRegistry::Tag).to receive(:delete) destroy_tag('rc1') end it 'makes it possible to delete a tag that ends with a dot' do - expect_delete_tags(%w[test.]) + expect_any_instance_of(ContainerRegistry::Tag).to receive(:delete) destroy_tag('test.') end @@ -127,12 +125,11 @@ describe Projects::Registry::TagsController do stub_container_registry_tags(repository: repository.path, tags: %w[rc1 test.]) end - let(:tags) { %w[tc1 test.] } - it 'makes it possible to delete tags in bulk' do - expect_delete_tags(tags) + allow_any_instance_of(ContainerRegistry::Tag).to receive(:delete) { |*args| ContainerRegistry::Tag.delete(*args) } + expect(ContainerRegistry::Tag).to receive(:delete).exactly(2).times - bulk_destroy_tags(tags) + bulk_destroy_tags(['rc1', 'test.']) end end end @@ -149,9 +146,4 @@ describe Projects::Registry::TagsController do format: :json end end - - def expect_delete_tags(tags, status = :success) - expect(service).to receive(:execute).with(repository) { { status: status } } - expect(Projects::ContainerRepository::DeleteTagsService).to receive(:new).with(repository.project, user, tags: tags) { service } - end end diff --git a/spec/controllers/projects/templates_controller_spec.rb b/spec/controllers/projects/templates_controller_spec.rb index 07b8a36fefc..d5ef2b0e114 100644 --- a/spec/controllers/projects/templates_controller_spec.rb +++ b/spec/controllers/projects/templates_controller_spec.rb @@ -99,44 +99,4 @@ describe Projects::TemplatesController do include_examples 'renders 404 when params are invalid' end end - - describe '#names' do - before do - project.add_developer(user) - sign_in(user) - end - - shared_examples 'template names request' do - it 'returns the template names' do - get(:names, params: { namespace_id: project.namespace, template_type: template_type, project_id: project }, format: :json) - - expect(response).to have_gitlab_http_status(200) - expect(json_response.size).to eq(1) - expect(json_response[0]['name']).to eq(expected_template_name) - end - - it 'fails for user with no access' do - other_user = create(:user) - sign_in(other_user) - - get(:names, params: { namespace_id: project.namespace, template_type: template_type, project_id: project }, format: :json) - - expect(response).to have_gitlab_http_status(404) - end - end - - context 'when querying for issue templates' do - it_behaves_like 'template names request' do - let(:template_type) { 'issue' } - let(:expected_template_name) { 'issue_template' } - end - end - - context 'when querying for merge_request templates' do - it_behaves_like 'template names request' do - let(:template_type) { 'merge_request' } - let(:expected_template_name) { 'merge_request_template' } - end - end - end end |