diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-01-24 14:40:11 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-01-24 14:40:11 +0100 |
commit | e4aac7f365105cbc7547239066db075a44d69788 (patch) | |
tree | 0b6301c542fdb64498e56352ee8bfb81f2a4e976 | |
parent | aa290573aece6408ad8bb98c7a04257202be5ff8 (diff) | |
download | gitlab-ce-e4aac7f365105cbc7547239066db075a44d69788.tar.gz |
Do not raise an error when trying to persist a job
-rw-r--r-- | app/models/commit_status.rb | 4 | ||||
-rw-r--r-- | app/services/ci/create_job_service.rb | 2 | ||||
-rw-r--r-- | lib/api/commit_statuses.rb | 2 | ||||
-rw-r--r-- | spec/services/ci/create_job_service_spec.rb | 6 |
4 files changed, 10 insertions, 4 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index f010b0ce9db..47af20975ec 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -51,8 +51,8 @@ class CommitStatus < ActiveRecord::Base # We still create some CommitStatuses outside of CreatePipelineService. # # These are pages deployments and external statuses. We now handle these - # using CreateJobService, but we still need to ensure that a job has a - # stage assigned. TODO, In future releases we will add model validation. + # jobs using CreateJobService, but we still need to ensure that a job has + # a stage assigned. TODO, In future releases we will add model validation. # before_create unless: :importing? do Ci::EnsureStageService.new(project, user).execute(self) do |stage| diff --git a/app/services/ci/create_job_service.rb b/app/services/ci/create_job_service.rb index 683c3557cd0..7cb77edd690 100644 --- a/app/services/ci/create_job_service.rb +++ b/app/services/ci/create_job_service.rb @@ -5,7 +5,7 @@ module Ci Ci::EnsureStageService.new(project, current_user) .execute(subject) - subject.save! + subject.save end end end diff --git a/lib/api/commit_statuses.rb b/lib/api/commit_statuses.rb index 76cb9a8c808..3ec17c4d9f5 100644 --- a/lib/api/commit_statuses.rb +++ b/lib/api/commit_statuses.rb @@ -96,7 +96,7 @@ module API if status.new_record? Ci::CreateJobService.new(@project, current_user).execute(status) else - status.save! + status.save if status.changed? end render_validation_error!(status) if status.invalid? diff --git a/spec/services/ci/create_job_service_spec.rb b/spec/services/ci/create_job_service_spec.rb index a7a8032ba28..d9dd1a40325 100644 --- a/spec/services/ci/create_job_service_spec.rb +++ b/spec/services/ci/create_job_service_spec.rb @@ -17,4 +17,10 @@ describe Ci::CreateJobService, '#execute' do it 'ensures that a job has a stage assigned' do expect(service.execute(status).stage_id).to be_present end + + it 'does not raise error if status is invalid' do + status.name = nil + + expect(service.execute(status)).not_to be_persisted + end end |