Commit e4aac7f3 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Do not raise an error when trying to persist a job

parent aa290573
...@@ -51,8 +51,8 @@ class CommitStatus < ActiveRecord::Base ...@@ -51,8 +51,8 @@ class CommitStatus < ActiveRecord::Base
# We still create some CommitStatuses outside of CreatePipelineService. # We still create some CommitStatuses outside of CreatePipelineService.
# #
# These are pages deployments and external statuses. We now handle these # These are pages deployments and external statuses. We now handle these
# using CreateJobService, but we still need to ensure that a job has a # jobs using CreateJobService, but we still need to ensure that a job has
# stage assigned. TODO, In future releases we will add model validation. # a stage assigned. TODO, In future releases we will add model validation.
# #
before_create unless: :importing? do before_create unless: :importing? do
Ci::EnsureStageService.new(project, user).execute(self) do |stage| Ci::EnsureStageService.new(project, user).execute(self) do |stage|
......
...@@ -5,7 +5,7 @@ module Ci ...@@ -5,7 +5,7 @@ module Ci
Ci::EnsureStageService.new(project, current_user) Ci::EnsureStageService.new(project, current_user)
.execute(subject) .execute(subject)
subject.save! subject.save
end end
end end
end end
......
...@@ -96,7 +96,7 @@ module API ...@@ -96,7 +96,7 @@ module API
if status.new_record? if status.new_record?
Ci::CreateJobService.new(@project, current_user).execute(status) Ci::CreateJobService.new(@project, current_user).execute(status)
else else
status.save! status.save if status.changed?
end end
render_validation_error!(status) if status.invalid? render_validation_error!(status) if status.invalid?
......
...@@ -17,4 +17,10 @@ describe Ci::CreateJobService, '#execute' do ...@@ -17,4 +17,10 @@ describe Ci::CreateJobService, '#execute' do
it 'ensures that a job has a stage assigned' do it 'ensures that a job has a stage assigned' do
expect(service.execute(status).stage_id).to be_present expect(service.execute(status).stage_id).to be_present
end end
it 'does not raise error if status is invalid' do
status.name = nil
expect(service.execute(status)).not_to be_persisted
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment