Skip to content

Commit ab6b9a1

Browse files
committed
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.
1 parent b07ac85 commit ab6b9a1

File tree

4 files changed

+2
-29
lines changed

4 files changed

+2
-29
lines changed

app/controllers/projects/artifacts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def build
8686
end
8787

8888
def build_from_id
89-
project.get_build(params[:job_id]) if params[:job_id]
89+
project.builds.find_by_id(params[:job_id]) if params[:job_id]
9090
end
9191

9292
def build_from_ref

app/controllers/projects/build_artifacts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def job
4545
end
4646

4747
def job_from_id
48-
project.get_build(params[:build_id]) if params[:build_id]
48+
project.builds.find_by_id(params[:build_id]) if params[:build_id]
4949
end
5050

5151
def job_from_ref

app/models/project.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,10 +658,6 @@ def latest_successful_build_for!(job_name, ref = default_branch)
658658
latest_successful_build_for(job_name, ref) || raise(ActiveRecord::RecordNotFound.new("Couldn't find job #{job_name}"))
659659
end
660660

661-
def get_build(id)
662-
builds.find_by(id: id)
663-
end
664-
665661
def merge_base_commit(first_commit_id, second_commit_id)
666662
sha = repository.merge_base(first_commit_id, second_commit_id)
667663
commit_by(oid: sha) if sha

spec/models/project_spec.rb

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,29 +2026,6 @@
20262026
end
20272027
end
20282028

2029-
describe '#get_build' do
2030-
let(:project) { create(:project, :repository) }
2031-
let(:ci_pipeline) { create(:ci_pipeline, project: project) }
2032-
2033-
context 'when build exists' do
2034-
context 'build is associated with project' do
2035-
let(:build) { create(:ci_build, :success, pipeline: ci_pipeline) }
2036-
2037-
it { expect(project.get_build(build.id)).to eq(build) }
2038-
end
2039-
2040-
context 'build is not associated with project' do
2041-
let(:build) { create(:ci_build, :success) }
2042-
2043-
it { expect(project.get_build(build.id)).to be_nil }
2044-
end
2045-
end
2046-
2047-
context 'build does not exists' do
2048-
it { expect(project.get_build(rand 100)).to be_nil }
2049-
end
2050-
end
2051-
20522029
describe '#import_status' do
20532030
context 'with import_state' do
20542031
it 'returns the right status' do

0 commit comments

Comments
 (0)