Commit d45da5a9 authored by Allison Browne's avatar Allison Browne

Optimize pipeline entity spec

Make database creation more efficent and
only add setup code where it is needed
parent 3e5374cc
......@@ -7,18 +7,8 @@ RSpec.describe PipelineEntity do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let(:request) { double('request') }
before do
stub_not_protect_default_branch
allow(request).to receive(:current_user).and_return(user)
allow(request).to receive(:project).and_return(project)
end
let(:entity) do
described_class.represent(pipeline, request: request)
end
let(:request) { double('request', current_user: user) }
let(:entity) { described_class.represent(pipeline, request: request) }
describe '#as_json' do
subject { entity.as_json }
......@@ -54,10 +44,13 @@ RSpec.describe PipelineEntity do
end
end
context 'when pipeline is retryable' do
let(:project) { create(:project) }
context 'when default branch not protected' do
before do
stub_not_protect_default_branch
end
let(:pipeline) do
context 'when pipeline is retryable' do
let_it_be(:pipeline) do
create(:ci_pipeline, status: :success, project: project)
end
......@@ -89,9 +82,7 @@ RSpec.describe PipelineEntity do
end
context 'when pipeline is cancelable' do
let(:project) { create(:project) }
let(:pipeline) do
let_it_be(:pipeline) do
create(:ci_pipeline, status: :running, project: project)
end
......@@ -121,6 +112,7 @@ RSpec.describe PipelineEntity do
end
end
end
end
context 'delete path' do
context 'user has ability to delete pipeline' do
......@@ -133,7 +125,6 @@ RSpec.describe PipelineEntity do
end
context 'user does not have ability to delete pipeline' do
let(:project) { create(:project) }
let(:pipeline) { create(:ci_pipeline, project: project) }
it 'does not contain delete path' do
......@@ -167,8 +158,13 @@ RSpec.describe PipelineEntity do
end
end
context 'when request has a project' do
before do
allow(request).to receive(:project).and_return(project)
end
context 'when pipeline is detached merge request pipeline' do
let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) }
let_it_be(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) }
let(:project) { merge_request.target_project }
let(:pipeline) { merge_request.pipelines_for_merge_request.first }
......@@ -216,7 +212,7 @@ RSpec.describe PipelineEntity do
end
context 'when pipeline is merge request pipeline' do
let(:merge_request) { create(:merge_request, :with_merge_request_pipeline, merge_sha: 'abc') }
let_it_be(:merge_request) { create(:merge_request, :with_merge_request_pipeline, merge_sha: 'abc') }
let(:project) { merge_request.target_project }
let(:pipeline) { merge_request.pipelines_for_merge_request.first }
......@@ -237,9 +233,10 @@ RSpec.describe PipelineEntity do
expect(subject[:merge_request_event_type]).to be_present
end
end
end
context 'when pipeline has failed builds' do
let_it_be(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let_it_be(:pipeline) { create(:ci_pipeline, user: user) }
let_it_be(:build) { create(:ci_build, :success, pipeline: pipeline) }
let_it_be(:failed_1) { create(:ci_build, :failed, pipeline: pipeline) }
let_it_be(:failed_2) { create(:ci_build, :failed, pipeline: pipeline) }
......
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