summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-08-04 00:46:58 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-08-04 01:04:18 +0800
commit94b3d33de1417b31ef3994e43f901941dc302ca0 (patch)
tree8bf841bbc5e531bb23377095fdb250261c1a96ee
parent3f7680a61933cd2f710236474b01e9cd9b849beb (diff)
downloadgitlab-ce-94b3d33de1417b31ef3994e43f901941dc302ca0.tar.gz
If we use Rails magic it's breaking this test:
spec/lib/gitlab/data_builder/pipeline_data_builder_spec.rb Because it would trigger the event just after saved and it would load no builds and cache it. We should really avoid adding more magic.
-rw-r--r--app/models/ci/pipeline.rb10
-rw-r--r--spec/models/ci/pipeline_spec.rb2
2 files changed, 5 insertions, 7 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 822ba7b6c00..ca41a998a2b 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -18,7 +18,6 @@ module Ci
# Invalidate object and save if when touched
after_touch :update_state
- after_save :execute_hooks_if_status_changed
after_save :keep_around_commits
# ref can't be HEAD or SHA, can only be branch/tag name
@@ -230,6 +229,7 @@ module Ci
def update_state
statuses.reload
+ last_status = status
self.status = if yaml_errors.blank?
statuses.latest.status || 'skipped'
else
@@ -238,11 +238,9 @@ module Ci
self.started_at = statuses.started_at
self.finished_at = statuses.finished_at
self.duration = statuses.latest.duration
- save
- end
-
- def execute_hooks_if_status_changed
- execute_hooks if status_changed? && !skip_ci?
+ saved = save
+ execute_hooks if last_status != status && saved && !skip_ci?
+ saved
end
def execute_hooks
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index b20c617f089..326d3c9b44d 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -551,7 +551,7 @@ describe Ci::Pipeline, models: true do
before do
WebMock.stub_request(:post, hook.url)
- pipeline.save
+ pipeline.touch
ProjectWebHookWorker.drain
end