Remove get_build method for find_by_id

The original intention of `get_build` was as a workaround not to violate
`CodeReuse/ActiveRecord`. `find_by_id` does the exact same thing but
does not violate the rubocop rule.
This commit is contained in:
Steve Azzopardi 2019-01-09 16:33:22 +01:00
parent b07ac850ef
commit ab6b9a1c43
No known key found for this signature in database
GPG Key ID: 605BD4706E7DB47D
4 changed files with 2 additions and 29 deletions

View File

@ -86,7 +86,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
end
def build_from_id
project.get_build(params[:job_id]) if params[:job_id]
project.builds.find_by_id(params[:job_id]) if params[:job_id]
end
def build_from_ref

View File

@ -45,7 +45,7 @@ class Projects::BuildArtifactsController < Projects::ApplicationController
end
def job_from_id
project.get_build(params[:build_id]) if params[:build_id]
project.builds.find_by_id(params[:build_id]) if params[:build_id]
end
def job_from_ref

View File

@ -658,10 +658,6 @@ class Project < ActiveRecord::Base
latest_successful_build_for(job_name, ref) || raise(ActiveRecord::RecordNotFound.new("Couldn't find job #{job_name}"))
end
def get_build(id)
builds.find_by(id: id)
end
def merge_base_commit(first_commit_id, second_commit_id)
sha = repository.merge_base(first_commit_id, second_commit_id)
commit_by(oid: sha) if sha

View File

@ -2026,29 +2026,6 @@ describe Project do
end
end
describe '#get_build' do
let(:project) { create(:project, :repository) }
let(:ci_pipeline) { create(:ci_pipeline, project: project) }
context 'when build exists' do
context 'build is associated with project' do
let(:build) { create(:ci_build, :success, pipeline: ci_pipeline) }
it { expect(project.get_build(build.id)).to eq(build) }
end
context 'build is not associated with project' do
let(:build) { create(:ci_build, :success) }
it { expect(project.get_build(build.id)).to be_nil }
end
end
context 'build does not exists' do
it { expect(project.get_build(rand 100)).to be_nil }
end
end
describe '#import_status' do
context 'with import_state' do
it 'returns the right status' do