From b043729d4959ab5cbfd4aff02ce8c8c4c8a9d26f Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 13 Jul 2016 23:23:05 +0800 Subject: [PATCH] Share more stuffs --- spec/requests/api/artifacts_spec.rb | 13 ++----------- .../projects/artifacts_controller_spec.rb | 18 ++++++------------ spec/requests/shared/artifacts_context.rb | 17 +++++++++++++++-- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/spec/requests/api/artifacts_spec.rb b/spec/requests/api/artifacts_spec.rb index 2b84c1a2072..393b8f85402 100644 --- a/spec/requests/api/artifacts_spec.rb +++ b/spec/requests/api/artifacts_spec.rb @@ -4,18 +4,9 @@ require_relative '../shared/artifacts_context' describe API::API, api: true do include ApiHelpers - let(:user) { create(:user) } - let(:project) { create(:project) } - let(:pipeline) do - create(:ci_pipeline, project: project, sha: project.commit('fix').sha) - end - let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) } - - before do - project.team << [user, :developer] - end - describe 'GET /projects/:id/artifacts/:ref_name/:build_name' do + include_context 'artifacts from ref and build name' + def path_from_ref(ref = pipeline.sha, build_name = build.name, _ = '') api("/projects/#{project.id}/artifacts/#{ref}/#{build_name}", user) end diff --git a/spec/requests/projects/artifacts_controller_spec.rb b/spec/requests/projects/artifacts_controller_spec.rb index 9722a9a1d64..26f6ee8d252 100644 --- a/spec/requests/projects/artifacts_controller_spec.rb +++ b/spec/requests/projects/artifacts_controller_spec.rb @@ -2,19 +2,13 @@ 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('fix').sha) - end - let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) } - - before do - login_as(user) - project.team << [user, :developer] - end - describe 'GET /:project/artifacts/:ref/:build_name/browse' do + include_context 'artifacts from ref and build name' + + before do + login_as(user) + end + def path_from_ref(ref = pipeline.sha, build_name = build.name, path = 'browse') search_namespace_project_artifacts_path( diff --git a/spec/requests/shared/artifacts_context.rb b/spec/requests/shared/artifacts_context.rb index 4333be6e1cd..03f7f248773 100644 --- a/spec/requests/shared/artifacts_context.rb +++ b/spec/requests/shared/artifacts_context.rb @@ -1,4 +1,17 @@ -shared_context 'artifacts from ref with 404' do +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) + 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) @@ -16,7 +29,7 @@ shared_context 'artifacts from ref with 404' do end end -shared_context 'artifacts from ref with 302' do +shared_examples 'artifacts from ref with 302' do context 'with sha' do before do get path_from_ref