diff --git a/app/models/project.rb b/app/models/project.rb index d6e37e66a8b11e57088cb9efa2eeb48e62f477b2..770ec1c8a68f396061ad46ffb81e6f37e797bd48 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -434,15 +434,8 @@ class Project < ActiveRecord::Base end def builds_for(ref = 'HEAD') - commit_object = commit(ref) - - if commit_object.nil? - Ci::Build.none - else - Ci::Build.joins(:pipeline). - merge(Ci::Pipeline.where(sha: commit_object.sha, - project: self)) - end + Ci::Build.joins(:pipeline). + merge(Ci::Pipeline.where(ref: ref, project: self)) end def merge_base_commit(first_commit_id, second_commit_id) diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index a57f0b6886c40a9f10a750d4ae66e818458b2968..53064138a50d590de9ddcd806a3967b8a4b00b94 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -5,7 +5,8 @@ describe Ci::Build, models: true do let(:pipeline) do create(:ci_pipeline, project: project, - sha: project.commit.id) + sha: project.commit.id, + ref: 'fix') end let(:build) { create(:ci_build, pipeline: pipeline) } @@ -698,7 +699,7 @@ describe Ci::Build, models: true do end it 'returns builds from ref' do - builds = project.latest_success_builds_for('HEAD') + builds = project.latest_success_builds_for('fix') expect(builds).to contain_exactly(build) end diff --git a/spec/requests/api/builds_spec.rb b/spec/requests/api/builds_spec.rb index bc6242a0d718a23031d6e93d8484662bf6fd63a6..fb0f066498abe63439145da46d63b6fade19037a 100644 --- a/spec/requests/api/builds_spec.rb +++ b/spec/requests/api/builds_spec.rb @@ -190,7 +190,7 @@ describe API::API, api: true do describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do include_context 'artifacts from ref and build name' - def path_from_ref(ref = pipeline.sha, job = build.name) + def path_from_ref(ref = pipeline.ref, job = build.name) api("/projects/#{project.id}/builds/artifacts/#{ref}/download?job=#{job}", user) end diff --git a/spec/requests/projects/artifacts_controller_spec.rb b/spec/requests/projects/artifacts_controller_spec.rb index c8a21f7d0ec757cb7861138e030d213f9787d0d5..1782d37008a76439b38a37e6d60b5634ac0301bb 100644 --- a/spec/requests/projects/artifacts_controller_spec.rb +++ b/spec/requests/projects/artifacts_controller_spec.rb @@ -10,7 +10,7 @@ describe Projects::ArtifactsController do end def path_from_ref( - ref = pipeline.sha, job = build.name, path = 'browse') + ref = pipeline.ref, job = build.name, path = 'browse') search_namespace_project_artifacts_path( project.namespace, project, diff --git a/spec/requests/shared/artifacts_context.rb b/spec/requests/shared/artifacts_context.rb index 0c9f33bfcb288e52d813de2512aae3b72863286b..ff74b72a0b3d423070060fcdc1a7e05011049a9a 100644 --- a/spec/requests/shared/artifacts_context.rb +++ b/spec/requests/shared/artifacts_context.rb @@ -2,7 +2,10 @@ shared_context 'artifacts from ref and build name' do let(:user) { create(:user) } let(:project) { create(:project) } let(:pipeline) do - create(:ci_pipeline, project: project, sha: project.commit('fix').sha) + create(:ci_pipeline, + project: project, + sha: project.commit('fix').sha, + ref: 'fix') end let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) } @@ -30,17 +33,10 @@ shared_examples 'artifacts from ref with 404' do end shared_examples 'artifacts from ref successfully' do - context 'with sha' do - before do - get path_from_ref - end - - it('gives the file') { verify } - end - context 'with regular branch' do before do - pipeline.update(sha: project.commit('master').sha) + pipeline.update(ref: 'master', + sha: project.commit('master').sha) end before do @@ -52,7 +48,8 @@ shared_examples 'artifacts from ref successfully' do context 'with branch name containing slash' do before do - pipeline.update(sha: project.commit('improve/awesome').sha) + pipeline.update(ref: 'improve/awesome', + sha: project.commit('improve/awesome').sha) end before do