Commit 604dbc21 authored by Kamil Trzciński's avatar Kamil Trzciński

Fix rspec failures

parent 4a09690e
...@@ -198,12 +198,14 @@ module Ci ...@@ -198,12 +198,14 @@ module Ci
def self.newest_first(ref: nil, limit: 100) def self.newest_first(ref: nil, limit: 100)
relation = order(id: :desc) relation = order(id: :desc)
relation = relation.where(ref: ref) if ref relation = relation.where(ref: ref) if ref
if limit if limit
ids = relation.limit(limit).select(:id) ids = relation.limit(limit).select(:id)
# MySQL does not support limit in subquery # MySQL does not support limit in subquery
ids = ids.pluck(:id) if Gitlab::Database.mysql? ids = ids.pluck(:id) if Gitlab::Database.mysql?
relation = relation.where(id: ids) relation = relation.where(id: ids)
end end
relation relation
end end
......
...@@ -1052,6 +1052,11 @@ describe Ci::Pipeline, :mailer do ...@@ -1052,6 +1052,11 @@ describe Ci::Pipeline, :mailer do
expect(described_class.newest_first.pluck(:status)) expect(described_class.newest_first.pluck(:status))
.to eq(%w[skipped failed success canceled]) .to eq(%w[skipped failed success canceled])
end end
it 'searches limited backlog' do
expect(described_class.newest_first(limit: 1).pluck(:status))
.to eq(%w[skipped])
end
end end
describe '.latest_status' do describe '.latest_status' do
......
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