Commit 796b5b57 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix-latest-pipeine-ordering-again' into 'master'

Order only for latest_successful_for

See merge request !8301
parents f8bab610 e60bf0d6
...@@ -93,11 +93,8 @@ module Ci ...@@ -93,11 +93,8 @@ module Ci
.select("max(#{quoted_table_name}.id)") .select("max(#{quoted_table_name}.id)")
.group(:ref, :sha) .group(:ref, :sha)
if ref relation = ref ? where(ref: ref) : self
where(id: max_id, ref: ref) relation.where(id: max_id)
else
where(id: max_id)
end
end end
def self.latest_status(ref = nil) def self.latest_status(ref = nil)
...@@ -105,7 +102,7 @@ module Ci ...@@ -105,7 +102,7 @@ module Ci
end end
def self.latest_successful_for(ref) def self.latest_successful_for(ref)
success.latest(ref).first success.latest(ref).order(id: :desc).first
end end
def self.truncate_sha(sha) def self.truncate_sha(sha)
......
---
title: Fix finding the latest pipeline
merge_request: 8301
author:
...@@ -464,6 +464,19 @@ describe Ci::Pipeline, models: true do ...@@ -464,6 +464,19 @@ describe Ci::Pipeline, models: true do
end end
end end
describe '.latest_successful_for' do
include_context 'with some outdated pipelines'
let!(:latest_successful_pipeline) do
create_pipeline(:success, 'ref', 'D')
end
it 'returns the latest successful pipeline' do
expect(described_class.latest_successful_for('ref')).
to eq(latest_successful_pipeline)
end
end
describe '#status' do describe '#status' do
let!(:build) { create(:ci_build, :created, pipeline: pipeline, name: 'test') } let!(:build) { create(:ci_build, :created, pipeline: pipeline, name: 'test') }
......
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