GitLab wurde aktualisiert. Dank regelmäßiger Updates bleibt das THM GitLab sicher und Sie profitieren von den neuesten Funktionen. Vielen Dank für Ihre Geduld.

Unverified Commit 935dc667 authored by Steve Azzopardi's avatar Steve Azzopardi
Browse files

Add explicit test for #latest_successful_build_for!

project.latest_successful_build_for! is being tested inside of `describe
explicit. In doing so some duplication was generated but not
`#latest_successful_build_for!` has full coverage unlike before.

Move `create_pipeline` & `create_build` as helper methods for this spec
to reduce duplication.
parent f9c8822a
......@@ -1104,13 +1104,13 @@
describe '#pipeline_for' do
let(:project) { create(:project, :repository) }
let!(:pipeline) { create_pipeline }
let!(:pipeline) { create_pipeline(project) }
shared_examples 'giving the correct pipeline' do
it { is_expected.to eq(pipeline) }
context 'return latest' do
let!(:pipeline2) { create_pipeline }
let!(:pipeline2) { create_pipeline(project) }
it { is_expected.to eq(pipeline2) }
end
......@@ -1127,13 +1127,6 @@
it_behaves_like 'giving the correct pipeline'
end
def create_pipeline
create(:ci_pipeline,
project: project,
ref: 'master',
sha: project.commit('master').sha)
end
end
describe '#builds_enabled' do
......@@ -1922,35 +1915,20 @@ def create_pipeline
end
describe '#latest_successful_build_for' do
def create_pipeline(status = 'success')
create(:ci_pipeline, project: project,
sha: project.commit.sha,
ref: project.default_branch,
status: status)
end
def create_build(new_pipeline = pipeline, name = 'test')
create(:ci_build, :success, :artifacts,
pipeline: new_pipeline,
status: new_pipeline.status,
name: name)
end
let(:project) { create(:project, :repository) }
let(:pipeline) { create_pipeline }
let(:pipeline) { create_pipeline(project) }
context 'with many builds' do
it 'gives the latest builds from latest pipeline' do
pipeline1 = create_pipeline
pipeline2 = create_pipeline
pipeline1 = create_pipeline(project)
pipeline2 = create_pipeline(project)
create_build(pipeline1, 'test')
create_build(pipeline1, 'test2')
build1_p2 = create_build(pipeline2, 'test')
create_build(pipeline2, 'test2')
single_build = project.latest_successful_build_for(build1_p2.name)
expect(single_build).to eq(build1_p2)
expect(project.latest_successful_build_for(build1_p2.name))
.to eq(build1_p2)
end
end
......@@ -1959,31 +1937,79 @@ def create_build(new_pipeline = pipeline, name = 'test')
context 'standalone pipeline' do
it 'returns builds for ref for default_branch' do
single_build = project.latest_successful_build_for(build.name)
expect(project.latest_successful_build_for(build.name))
.to eq(build)
end
expect(single_build).to eq(build)
it 'returns empty relation if the build cannot be found' do
expect(project.latest_successful_build_for('TAIL'))
.to be_nil
end
end
it 'returns empty relation if the build cannot be found for #latest_successful_build_for' do
builds = project.latest_successful_build_for('TAIL')
context 'with some pending pipeline' do
before do
create_build(create_pipeline(project, 'pending'))
end
expect(builds).to be_nil
it 'gives the latest build from latest pipeline' do
expect(project.latest_successful_build_for(build.name))
.to eq(build)
end
end
end
context 'with pending pipeline' do
it 'returns empty relation' do
pipeline.update(status: 'pending')
pending_build = create_build(pipeline)
it 'returns exception if the build cannot be found for #latest_successful_build_for!' do
expect { project.latest_successful_build_for!(build.name, 'TAIL') }.to raise_error(ActiveRecord::RecordNotFound)
expect(project.latest_successful_build_for(pending_build.name)).to be_nil
end
end
end
describe '#latest_successful_build_for!' do
let(:project) { create(:project, :repository) }
let(:pipeline) { create_pipeline(project) }
context 'with many builds' do
it 'gives the latest builds from latest pipeline' do
pipeline1 = create_pipeline(project)
pipeline2 = create_pipeline(project)
create_build(pipeline1, 'test')
create_build(pipeline1, 'test2')
build1_p2 = create_build(pipeline2, 'test')
create_build(pipeline2, 'test2')
expect(project.latest_successful_build_for(build1_p2.name))
.to eq(build1_p2)
end
end
context 'with succeeded pipeline' do
let!(:build) { create_build }
context 'standalone pipeline' do
it 'returns builds for ref for default_branch' do
expect(project.latest_successful_build_for!(build.name))
.to eq(build)
end
it 'returns exception if the build cannot be found' do
expect { project.latest_successful_build_for!(build.name, 'TAIL') }
.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'with some pending pipeline' do
before do
create_build(create_pipeline('pending'))
create_build(create_pipeline(project, 'pending'))
end
it 'gives the latest build from latest pipeline' do
last_single_build = project.latest_successful_build_for(build.name)
expect(last_single_build).to eq(build)
expect(project.latest_successful_build_for!(build.name))
.to eq(build)
end
end
end
......@@ -1993,9 +2019,8 @@ def create_build(new_pipeline = pipeline, name = 'test')
pipeline.update(status: 'pending')
pending_build = create_build(pipeline)
expect(project.latest_successful_build_for(pending_build.name)).to be_nil
expect { project.latest_successful_build_for!(pending_build.name) }.to raise_error(ActiveRecord::RecordNotFound)
expect { project.latest_successful_build_for!(pending_build.name) }
.to raise_error(ActiveRecord::RecordNotFound)
end
end
end
......@@ -4365,4 +4390,18 @@ def domain_variable
def rugged_config
rugged_repo(project.repository).config
end
def create_pipeline(project, status = 'success')
create(:ci_pipeline, project: project,
sha: project.commit.sha,
ref: project.default_branch,
status: status)
end
def create_build(new_pipeline = pipeline, name = 'test')
create(:ci_build, :success, :artifacts,
pipeline: new_pipeline,
status: new_pipeline.status,
name: name)
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment