Commit e9db56dc authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'pl-spec-issues-build-tiny-refactor' into 'master'

Organize specs issue build service around features not roles

See merge request gitlab-org/gitlab!72609
parents c6479a09 48110d21
...@@ -140,76 +140,63 @@ RSpec.describe Issues::BuildService do ...@@ -140,76 +140,63 @@ RSpec.describe Issues::BuildService do
end end
describe '#execute' do describe '#execute' do
context 'as developer' do describe 'setting milestone' do
it 'builds a new issues with given params' do context 'when developer' do
milestone = create(:milestone, project: project) it 'builds a new issues with given params' do
issue = build_issue(milestone_id: milestone.id) milestone = create(:milestone, project: project)
issue = build_issue(milestone_id: milestone.id)
expect(issue.milestone).to eq(milestone)
expect(issue.issue_type).to eq('issue') expect(issue.milestone).to eq(milestone)
expect(issue.work_item_type.base_type).to eq('issue') end
end
it 'sets milestone to nil if it is not available for the project' do it 'sets milestone to nil if it is not available for the project' do
milestone = create(:milestone, project: create(:project)) milestone = create(:milestone, project: create(:project))
issue = build_issue(milestone_id: milestone.id) issue = build_issue(milestone_id: milestone.id)
expect(issue.milestone).to be_nil expect(issue.milestone).to be_nil
end
end end
context 'when issue_type is incident' do context 'when guest' do
it 'sets the correct issue type' do let(:user) { guest }
issue = build_issue(issue_type: 'incident')
expect(issue.issue_type).to eq('incident') it 'cannot set milestone' do
expect(issue.work_item_type.base_type).to eq('incident') milestone = create(:milestone, project: project)
issue = build_issue(milestone_id: milestone.id)
expect(issue.milestone).to be_nil
end end
end end
end end
context 'as guest' do describe 'setting issue type' do
let(:user) { guest } context 'with a corresponding WorkItem::Type' do
let_it_be(:type_issue_id) { WorkItem::Type.default_issue_type.id }
it 'cannot set milestone' do let_it_be(:type_incident_id) { WorkItem::Type.default_by_type(:incident).id }
milestone = create(:milestone, project: project)
issue = build_issue(milestone_id: milestone.id) where(:issue_type, :current_user, :work_item_type_id, :resulting_issue_type) do
nil | ref(:guest) | ref(:type_issue_id) | 'issue'
'issue' | ref(:guest) | ref(:type_issue_id) | 'issue'
'incident' | ref(:guest) | ref(:type_incident_id) | 'incident'
# update once support for test_case is enabled
'test_case' | ref(:guest) | ref(:type_issue_id) | 'issue'
# update once support for requirement is enabled
'requirement' | ref(:guest) | ref(:type_issue_id) | 'issue'
'invalid' | ref(:guest) | ref(:type_issue_id) | 'issue'
# ensure that we don't set a value which has a permission check but is an invalid issue type
'project' | ref(:guest) | ref(:type_issue_id) | 'issue'
end
expect(issue.milestone).to be_nil with_them do
end let(:user) { current_user }
context 'setting issue type' do it 'builds an issue' do
shared_examples 'builds an issue' do
specify do
issue = build_issue(issue_type: issue_type) issue = build_issue(issue_type: issue_type)
expect(issue.issue_type).to eq(resulting_issue_type) expect(issue.issue_type).to eq(resulting_issue_type)
expect(issue.work_item_type_id).to eq(work_item_type_id) expect(issue.work_item_type_id).to eq(work_item_type_id)
end end
end end
it 'cannot set invalid issue type' do
issue = build_issue(issue_type: 'project')
expect(issue).to be_issue
end
context 'with a corresponding WorkItem::Type' do
let_it_be(:type_issue_id) { WorkItem::Type.default_issue_type.id }
let_it_be(:type_incident_id) { WorkItem::Type.default_by_type(:incident).id }
where(:issue_type, :work_item_type_id, :resulting_issue_type) do
nil | ref(:type_issue_id) | 'issue'
'issue' | ref(:type_issue_id) | 'issue'
'incident' | ref(:type_incident_id) | 'incident'
'test_case' | ref(:type_issue_id) | 'issue' # update once support for test_case is enabled
'requirement' | ref(:type_issue_id) | 'issue' # update once support for requirement is enabled
'invalid' | ref(:type_issue_id) | 'issue'
end
with_them do
it_behaves_like 'builds an issue'
end
end
end end
end end
end end
......
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