summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-07-21 19:09:46 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-07-21 19:09:46 +0800
commitfa02d8fcc588b3720640131e7cc9ef7b06470932 (patch)
tree2e80e28cdbfa943198d6c631a9fdea43af298c6c /spec
parent69d0671342f361f48001c1c9bb4571cd881fdca8 (diff)
downloadgitlab-ce-fa02d8fcc588b3720640131e7cc9ef7b06470932.tar.gz
Merge shared context into controller test and update accordingly
Diffstat (limited to 'spec')
-rw-r--r--spec/requests/projects/artifacts_controller_spec.rb77
-rw-r--r--spec/requests/shared/artifacts_context.rb101
2 files changed, 62 insertions, 116 deletions
diff --git a/spec/requests/projects/artifacts_controller_spec.rb b/spec/requests/projects/artifacts_controller_spec.rb
index 1782d37008a..b823676d9e1 100644
--- a/spec/requests/projects/artifacts_controller_spec.rb
+++ b/spec/requests/projects/artifacts_controller_spec.rb
@@ -1,9 +1,20 @@
require 'spec_helper'
-require_relative '../shared/artifacts_context'
describe Projects::ArtifactsController do
+ let(:user) { create(:user) }
+ let(:project) { create(:project) }
+ let(:pipeline) do
+ create(:ci_pipeline,
+ project: project,
+ sha: project.commit.sha,
+ ref: project.default_branch)
+ end
+ let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
+
describe 'GET /:project/builds/artifacts/:ref_name/browse?job=name' do
- include_context 'artifacts from ref and build name'
+ before do
+ project.team << [user, :developer]
+ end
before do
login_as(user)
@@ -19,33 +30,69 @@ describe Projects::ArtifactsController do
job: job)
end
- context '404' do
- def verify
- expect(response.status).to eq(404)
+ context 'cannot find the build' do
+ shared_examples 'not found' do
+ it { expect(response).to have_http_status(:not_found) }
end
- it_behaves_like 'artifacts from ref with 404'
+ context 'has no such ref' do
+ before do
+ get path_from_ref('TAIL', build.name)
+ end
+
+ it_behaves_like 'not found'
+ end
+
+ context 'has no such build' do
+ before do
+ get path_from_ref(pipeline.ref, 'NOBUILD')
+ end
+
+ it_behaves_like 'not found'
+ end
context 'has no path' do
before do
get path_from_ref(pipeline.sha, build.name, '')
end
- it('gives 404') { verify }
+ it_behaves_like 'not found'
end
end
- context '302' do
- def verify
- path = browse_namespace_project_build_artifacts_path(
- project.namespace,
- project,
- build)
+ context 'found the build and redirect' do
+ shared_examples 'redirect to the build' do
+ it 'redirects' do
+ path = browse_namespace_project_build_artifacts_path(
+ project.namespace,
+ project,
+ build)
- expect(response).to redirect_to(path)
+ expect(response).to redirect_to(path)
+ end
+ end
+
+ context 'with regular branch' do
+ before do
+ pipeline.update(ref: 'master',
+ sha: project.commit('master').sha)
+
+ get path_from_ref('master')
+ end
+
+ it_behaves_like 'redirect to the build'
end
- it_behaves_like 'artifacts from ref successfully'
+ context 'with branch name containing slash' do
+ before do
+ pipeline.update(ref: 'improve/awesome',
+ sha: project.commit('improve/awesome').sha)
+
+ get path_from_ref('improve/awesome')
+ end
+
+ it_behaves_like 'redirect to the build'
+ end
end
end
end
diff --git a/spec/requests/shared/artifacts_context.rb b/spec/requests/shared/artifacts_context.rb
deleted file mode 100644
index 102ae392844..00000000000
--- a/spec/requests/shared/artifacts_context.rb
+++ /dev/null
@@ -1,101 +0,0 @@
-shared_context 'artifacts from ref and build name' do
- let(:user) { create(:user) }
- let(:project) { create(:project) }
- let(:pipeline) do
- create(:ci_pipeline,
- project: project,
- sha: project.commit('fix').sha,
- ref: 'fix')
- end
- let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
-
- before do
- project.team << [user, :developer]
- end
-end
-
-shared_examples 'artifacts from ref with 404' do
- context 'has no such ref' do
- before do
- get path_from_ref('TAIL', build.name)
- end
-
- it('gives 404') { verify }
- end
-
- context 'has no such build' do
- before do
- get path_from_ref(pipeline.ref, 'NOBUILD')
- end
-
- it('gives 404') { verify }
- end
-end
-
-shared_examples 'artifacts from ref successfully' do
- def create_new_pipeline(status)
- new_pipeline = create(:ci_pipeline, status: 'success')
- create(:ci_build, status, :artifacts, pipeline: new_pipeline)
- end
-
- context 'with sha' do
- before do
- get path_from_ref(pipeline.sha)
- end
-
- it('gives the file') { verify }
- end
-
- context 'with regular branch' do
- before do
- pipeline.update(ref: 'master',
- sha: project.commit('master').sha)
- end
-
- before do
- get path_from_ref('master')
- end
-
- it('gives the file') { verify }
- end
-
- context 'with branch name containing slash' do
- before do
- pipeline.update(ref: 'improve/awesome',
- sha: project.commit('improve/awesome').sha)
- end
-
- before do
- get path_from_ref('improve/awesome')
- end
-
- it('gives the file') { verify }
- end
-
- context 'with latest pipeline' do
- before do
- 3.times do # creating some old pipelines
- create_new_pipeline(:success)
- end
- end
-
- before do
- get path_from_ref
- end
-
- it('gives the file') { verify }
- end
-
- context 'with success pipeline' do
- before do
- build # make sure pipeline was old, but still the latest success one
- create_new_pipeline(:pending)
- end
-
- before do
- get path_from_ref
- end
-
- it('gives the file') { verify }
- end
-end