diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-07-20 19:13:32 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-07-20 19:13:32 +0800 |
commit | 66c8c3d4c390f886306c5bc074f9c0b3298f6911 (patch) | |
tree | 5d2a95a7139ce1da27e6c8d11511cc6692b7a987 | |
parent | 2fe8ebc143737390ea8ba952ad1b8ba4c82dae84 (diff) | |
download | gitlab-ce-66c8c3d4c390f886306c5bc074f9c0b3298f6911.tar.gz |
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.
-rw-r--r-- | spec/models/project_spec.rb | 68 | ||||
-rw-r--r-- | spec/requests/api/builds_spec.rb | 38 |
2 files changed, 60 insertions, 46 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index b03fdebf8e7..373170f9769 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -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 diff --git a/spec/requests/api/builds_spec.rb b/spec/requests/api/builds_spec.rb index 553b432c7c7..6e84604c949 100644 --- a/spec/requests/api/builds_spec.rb +++ b/spec/requests/api/builds_spec.rb @@ -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 |