Commit dddd2db7 authored by Hordur Freyr Yngvason's avatar Hordur Freyr Yngvason

Refactor error case into shared examples

parent 619d7d69
......@@ -84,10 +84,8 @@ describe Clusters::CreateService do
let(:management_project_namespace) { project.namespace }
let(:management_project) { create(:project, namespace: management_project_namespace) }
context 'management_project is non-existent' do
let(:management_project_id) { 0 }
it 'does not persist the cluster' do
shared_examples 'invalid project or cluster permissions' do
it 'does not persist the cluster and adds errors' do
expect(cluster).not_to be_persisted
expect(cluster.errors[:management_project_id]).to include('Project does not exist or you don\'t have permission to perform this action')
......@@ -108,11 +106,7 @@ describe Clusters::CreateService do
end
context 'when user is not authorized to adminster manangement_project' do
it 'does not persist the cluster' do
expect(cluster).not_to be_persisted
expect(cluster.errors[:management_project_id]).to include('Project does not exist or you don\'t have permission to perform this action')
end
include_examples 'invalid project or cluster permissions'
end
end
......@@ -128,6 +122,12 @@ describe Clusters::CreateService do
end
end
context 'management_project is non-existent' do
let(:management_project_id) { 0 }
include_examples 'invalid project or cluster permissions'
end
context 'project cluster' do
include_examples 'setting a management project'
include_examples 'setting a management project outside of scope'
......
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