Commit 32223ae7 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch '321631-fix-wrong-query' into 'master'

Fix update-older-statuses query

See merge request gitlab-org/gitlab!57156
parents f56372f5 65d1adb6
...@@ -293,7 +293,8 @@ class CommitStatus < ApplicationRecord ...@@ -293,7 +293,8 @@ class CommitStatus < ApplicationRecord
end end
def update_older_statuses_retried! def update_older_statuses_retried!
self.class pipeline
.statuses
.latest .latest
.where(name: name) .where(name: name)
.where.not(id: id) .where.not(id: id)
......
...@@ -870,4 +870,23 @@ RSpec.describe CommitStatus do ...@@ -870,4 +870,23 @@ RSpec.describe CommitStatus do
it { is_expected.to eq(false) } it { is_expected.to eq(false) }
end end
end end
describe '#update_older_statuses_retried!' do
let!(:build_old) { create_status(name: 'build') }
let!(:build_new) { create_status(name: 'build') }
let!(:test) { create_status(name: 'test') }
let!(:build_from_other_pipeline) do
new_pipeline = create(:ci_pipeline, project: project, sha: project.commit.id)
create_status(name: 'build', pipeline: new_pipeline)
end
it "updates 'retried' and 'status' columns of the latest status with the same name in the same pipeline" do
build_new.update_older_statuses_retried!
expect(build_new.reload).to have_attributes(retried: false, processed: false)
expect(build_old.reload).to have_attributes(retried: true, processed: true)
expect(test.reload).to have_attributes(retried: false, processed: false)
expect(build_from_other_pipeline.reload).to have_attributes(retried: false, processed: false)
end
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