We need INNER JOIN to get the right pipeline,

also added a test for checking this.
This commit is contained in:
Lin Jen-Shin 2016-07-20 18:06:35 +08:00
parent 3925436a95
commit 2fe8ebc143
2 changed files with 8 additions and 5 deletions

View File

@ -431,7 +431,7 @@ class Project < ActiveRecord::Base
# ref can't be HEAD, can only be branch/tag name or SHA
def latest_successful_builds_for(ref = default_branch)
builds.where(pipeline: pipelines.latest_successful_for(ref)).
Ci::Build.joins(:pipeline).merge(pipelines.latest_successful_for(ref)).
latest_successful_with_artifacts
end

View File

@ -256,14 +256,17 @@ describe API::API, api: true do
context 'with latest pipeline' do
before do
pipelines = Array.new(3).map do # creating some old pipelines
old_pipelines = Array.new(3).map do # creating some old pipelines
create(:ci_pipeline, status: 'success')
end
pipelines.reverse_each do |pipe|
new_build = create(:ci_build, :success, pipeline: pipe)
new_build.update(artifacts_file: another_artifacts)
old_pipelines.reverse_each do |pipe|
old_build = create(:ci_build, :success, pipeline: pipe)
old_build.update(artifacts_file: another_artifacts)
end
wrong_build = create(:ci_build, :success, pipeline: pipeline)
wrong_build.update(artifacts_file: another_artifacts)
end
before do