From 92d361c8d34d3ef29ff546ed1f7b74ce9a8f81f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Sun, 11 Mar 2018 23:51:10 +0100 Subject: Add empty repo check before running AutoDevOps pipeline --- .../projects/pipelines_settings_controller_spec.rb | 34 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/controllers/projects/pipelines_settings_controller_spec.rb b/spec/controllers/projects/pipelines_settings_controller_spec.rb index 1cc488bef32..0dd8575e2b7 100644 --- a/spec/controllers/projects/pipelines_settings_controller_spec.rb +++ b/spec/controllers/projects/pipelines_settings_controller_spec.rb @@ -47,10 +47,38 @@ describe Projects::PipelinesSettingsController do expect_any_instance_of(Projects::UpdateService).to receive(:run_auto_devops_pipeline?).and_return(true) end - it 'queues a CreatePipelineWorker' do - expect(CreatePipelineWorker).to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args) + context 'when the project repository is empty' do + before do + allow_any_instance_of(Project).to receive(:empty_repo?).and_return(true) + end - subject + it 'sets a warning flash' do + expect(subject).to set_flash[:warning] + end + + it 'does not queue a CreatePipelineWorker' do + expect(CreatePipelineWorker).not_to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args) + + subject + end + end + + context 'when the project repository is not empty' do + before do + allow_any_instance_of(Project).to receive(:empty_repo?).and_return(false) + end + + it 'sets a success flash' do + allow(CreatePipelineWorker).to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args) + + expect(subject).to set_flash[:success] + end + + it 'queues a CreatePipelineWorker' do + expect(CreatePipelineWorker).to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args) + + subject + end end end -- cgit v1.2.1 From 92d51da23dfa3e83fb87fd381553a1fd93d49614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Thu, 22 Mar 2018 13:33:24 +0100 Subject: Use actual repo instead of stubbing method --- spec/controllers/projects/pipelines_settings_controller_spec.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'spec') diff --git a/spec/controllers/projects/pipelines_settings_controller_spec.rb b/spec/controllers/projects/pipelines_settings_controller_spec.rb index 0dd8575e2b7..913b9bd804a 100644 --- a/spec/controllers/projects/pipelines_settings_controller_spec.rb +++ b/spec/controllers/projects/pipelines_settings_controller_spec.rb @@ -48,10 +48,6 @@ describe Projects::PipelinesSettingsController do end context 'when the project repository is empty' do - before do - allow_any_instance_of(Project).to receive(:empty_repo?).and_return(true) - end - it 'sets a warning flash' do expect(subject).to set_flash[:warning] end @@ -64,9 +60,7 @@ describe Projects::PipelinesSettingsController do end context 'when the project repository is not empty' do - before do - allow_any_instance_of(Project).to receive(:empty_repo?).and_return(false) - end + let(:project) { create(:project, :repository) } it 'sets a success flash' do allow(CreatePipelineWorker).to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args) -- cgit v1.2.1