Commit 66c8c3d4 authored by Lin Jen-Shin's avatar Lin Jen-Shin

More complex data manipulating tests to model, and

this should properly test that it's really getting the
builds from the latest successful pipelines and latest
successful builds.
parent 2fe8ebc1
......@@ -1124,22 +1124,74 @@ describe Project, models: true do
status: 'success')
end
let!(:build) do
let(:build) do
create(:ci_build, :artifacts, :success, pipeline: pipeline)
end
context 'with succeed pipeline' do
it 'returns builds for ref for default_branch' do
builds = project.latest_successful_builds_for
context 'standalone pipeline' do
before do
build
end
it 'returns builds for ref for default_branch' do
builds = project.latest_successful_builds_for
expect(builds).to contain_exactly(build)
end
it 'returns empty relation if the build cannot be found' do
builds = project.latest_successful_builds_for('TAIL')
expect(builds).to contain_exactly(build)
expect(builds).to be_kind_of(ActiveRecord::Relation)
expect(builds).to be_empty
end
end
it 'returns empty relation if the build cannot be found' do
builds = project.latest_successful_builds_for('TAIL')
context 'with multiple pipelines and builds' do
shared_examples 'latest successful one' do
it 'gives the latest build from latest pipeline' do
latest_build = project.latest_successful_builds_for.first
expect(builds).to be_kind_of(ActiveRecord::Relation)
expect(builds).to be_empty
expect(latest_build).to eq(build)
end
end
context 'with all success pipeline' do
before do
old_pipelines = Array.new(3).map do
create(:ci_pipeline, project: project,
sha: project.commit.sha,
ref: project.default_branch,
status: 'success')
end
# should not give this old build for the latest pipeline
create(:ci_build, :success, :artifacts, pipeline: pipeline)
build
old_pipelines.reverse_each do |pipe|
create(:ci_build, :success, :artifacts, pipeline: pipe)
end
end
it_behaves_like 'latest successful one'
end
context 'with some pending pipeline' do
before do
# make sure pipeline was old, but still the latest success one
build
new_pipeline = create(:ci_pipeline, project: project,
sha: project.commit.sha,
ref: project.default_branch,
status: 'pending')
create(:ci_build, :pending, :artifacts, pipeline: new_pipeline)
end
it_behaves_like 'latest successful one'
end
end
end
......
......@@ -253,44 +253,6 @@ describe API::API, api: true do
it_behaves_like 'a valid file'
end
context 'with latest pipeline' do
before do
old_pipelines = Array.new(3).map do # creating some old pipelines
create(:ci_pipeline, status: 'success')
end
old_pipelines.reverse_each do |pipe|
old_build = create(:ci_build, :success, pipeline: pipe)
old_build.update(artifacts_file: another_artifacts)
end
wrong_build = create(:ci_build, :success, pipeline: pipeline)
wrong_build.update(artifacts_file: another_artifacts)
end
before do
get path_for_ref
end
it_behaves_like 'a valid file'
end
context 'with success pipeline' do
before do
build # make sure pipeline was old, but still the latest success one
new_pipeline = create(:ci_pipeline, status: 'success')
new_build = create(:ci_build, :pending,
pipeline: new_pipeline)
new_build.update(artifacts_file: another_artifacts)
end
before do
get path_for_ref
end
it_behaves_like 'a valid file'
end
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