summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorSteve Azzopardi <steveazz@outlook.com>2018-12-06 11:55:50 +0100
committerSteve Azzopardi <steveazz@outlook.com>2019-01-07 17:29:26 +0100
commitf9c8822afdddcd83434432dc2c36b87cc1886602 (patch)
treee63fac7d0564ec0d948221188ff64941a67c42bc /spec/models
parent7ac32ae282fa2d35a3651de08f35aad1b85ffca0 (diff)
downloadgitlab-ce-f9c8822afdddcd83434432dc2c36b87cc1886602.tar.gz
Create `get_build` for project model
Inside of `Projects::ArtifactsController` and `Projects::BuildArtifactsController` we fetching the build by id using active record directly which violates `CodeReuse/ActiveRecord` rubocop rule. Create `get_build` inside of `project` model which does the same thing.
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/project_spec.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index aa4ec6493db..b12b81f8f38 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -2000,6 +2000,29 @@ 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