diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/models/merge_request/metrics_spec.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/models/merge_request/metrics_spec.rb')
-rw-r--r-- | spec/models/merge_request/metrics_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/models/merge_request/metrics_spec.rb b/spec/models/merge_request/metrics_spec.rb index a4bdac39074..8d1d503b323 100644 --- a/spec/models/merge_request/metrics_spec.rb +++ b/spec/models/merge_request/metrics_spec.rb @@ -54,4 +54,43 @@ RSpec.describe MergeRequest::Metrics do let!(:parent) { create(:ci_pipeline, project: merge_request.target_project) } let!(:model) { merge_request.metrics.tap { |metrics| metrics.update!(pipeline: parent) } } end + + describe 'update' do + let(:merge_request) { create(:merge_request) } + let(:metrics) { merge_request.metrics } + + before do + metrics.update!( + pipeline_id: 1, + latest_build_started_at: Time.current, + latest_build_finished_at: Time.current + ) + end + + context 'when pipeline_id is nullified' do + before do + metrics.update!(pipeline_id: nil) + end + + it 'nullifies build related columns via DB trigger' do + metrics.reload + + expect(metrics.latest_build_started_at).to be_nil + expect(metrics.latest_build_finished_at).to be_nil + end + end + + context 'when updated but pipeline_id is not nullified' do + before do + metrics.update!(latest_closed_at: Time.current) + end + + it 'does not nullify build related columns' do + metrics.reload + + expect(metrics.latest_build_started_at).not_to be_nil + expect(metrics.latest_build_finished_at).not_to be_nil + end + end + end end |