diff options
author | Steve Azzopardi <steveazz@outlook.com> | 2018-12-06 11:55:50 +0100 |
---|---|---|
committer | Steve Azzopardi <steveazz@outlook.com> | 2019-01-07 17:29:26 +0100 |
commit | f9c8822afdddcd83434432dc2c36b87cc1886602 (patch) | |
tree | e63fac7d0564ec0d948221188ff64941a67c42bc /spec/models | |
parent | 7ac32ae282fa2d35a3651de08f35aad1b85ffca0 (diff) | |
download | gitlab-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.rb | 23 |
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 |