debian-mirror-gitlab/spec/services/issues/create_service_spec.rb

141 lines
4.2 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
2015-12-23 02:04:40 +05:30
describe Issues::CreateService, services: true do
2014-09-02 18:07:02 +05:30
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
2016-06-02 11:05:42 +05:30
describe '#execute' do
let(:issue) { described_class.new(project, user, opts).execute }
context 'when params are valid' do
let(:assignee) { create(:user) }
let(:milestone) { create(:milestone, project: project) }
let(:labels) { create_pair(:label, project: project) }
2014-09-02 18:07:02 +05:30
before do
project.team << [user, :master]
2016-04-02 18:10:28 +05:30
project.team << [assignee, :master]
2016-06-02 11:05:42 +05:30
end
2016-04-02 18:10:28 +05:30
2016-06-02 11:05:42 +05:30
let(:opts) do
{ title: 'Awesome issue',
2016-04-02 18:10:28 +05:30
description: 'please fix',
2016-11-03 12:29:30 +05:30
assignee_id: assignee.id,
2016-06-02 11:05:42 +05:30
label_ids: labels.map(&:id),
2016-11-03 12:29:30 +05:30
milestone_id: milestone.id,
due_date: Date.tomorrow }
2014-09-02 18:07:02 +05:30
end
2016-11-03 12:29:30 +05:30
it 'creates the issue with the given params' do
expect(issue).to be_persisted
expect(issue.title).to eq('Awesome issue')
expect(issue.assignee).to eq assignee
expect(issue.labels).to match_array labels
expect(issue.milestone).to eq milestone
expect(issue.due_date).to eq Date.tomorrow
end
context 'when current user cannot admin issues in the project' do
let(:guest) { create(:user) }
before do
project.team << [guest, :guest]
end
it 'filters out params that cannot be set without the :admin_issue permission' do
issue = described_class.new(project, guest, opts).execute
expect(issue).to be_persisted
expect(issue.title).to eq('Awesome issue')
expect(issue.assignee).to be_nil
expect(issue.labels).to be_empty
expect(issue.milestone).to be_nil
expect(issue.due_date).to be_nil
end
end
2016-04-02 18:10:28 +05:30
it 'creates a pending todo for new assignee' do
attributes = {
project: project,
author: user,
user: assignee,
2016-06-02 11:05:42 +05:30
target_id: issue.id,
target_type: issue.class.name,
2016-04-02 18:10:28 +05:30
action: Todo::ASSIGNED,
state: :pending
}
expect(Todo.where(attributes).count).to eq 1
end
2016-06-02 11:05:42 +05:30
2016-11-03 12:29:30 +05:30
context 'when label belongs to project group' do
let(:group) { create(:group) }
let(:group_labels) { create_pair(:group_label, group: group) }
let(:opts) do
{
title: 'Title',
description: 'Description',
label_ids: group_labels.map(&:id)
}
end
before do
project.update(group: group)
end
it 'assigns group labels' do
expect(issue.labels).to match_array group_labels
end
end
2016-06-02 11:05:42 +05:30
context 'when label belongs to different project' do
let(:label) { create(:label) }
let(:opts) do
{ title: 'Title',
description: 'Description',
label_ids: [label.id] }
end
it 'does not assign label' do
expect(issue.labels).not_to include label
2016-06-02 11:05:42 +05:30
end
end
context 'when milestone belongs to different project' do
let(:milestone) { create(:milestone) }
let(:opts) do
{ title: 'Title',
description: 'Description',
milestone_id: milestone.id }
end
it 'does not assign milestone' do
expect(issue.milestone).not_to eq milestone
2016-06-02 11:05:42 +05:30
end
end
2016-09-29 09:46:39 +05:30
it 'executes issue hooks when issue is not confidential' do
opts = { title: 'Title', description: 'Description', confidential: false }
expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :issue_hooks)
expect(project).to receive(:execute_services).with(an_instance_of(Hash), :issue_hooks)
described_class.new(project, user, opts).execute
end
it 'executes confidential issue hooks when issue is confidential' do
opts = { title: 'Title', description: 'Description', confidential: true }
expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :confidential_issue_hooks)
expect(project).to receive(:execute_services).with(an_instance_of(Hash), :confidential_issue_hooks)
described_class.new(project, user, opts).execute
end
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it_behaves_like 'new issuable record that supports slash commands'
2014-09-02 18:07:02 +05:30
end
end