2014-04-02 06:38:35 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:49 -05:00
|
|
|
describe Issues::CreateService, services: true do
|
2014-04-02 06:38:35 -04:00
|
|
|
let(:project) { create(:empty_project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2016-04-21 07:40:52 -04:00
|
|
|
describe '#execute' do
|
|
|
|
let(:issue) { described_class.new(project, user, opts).execute }
|
2016-04-21 06:25:21 -04:00
|
|
|
|
2016-04-21 07:40:52 -04:00
|
|
|
context 'when params are valid' do
|
2016-04-21 06:46:48 -04:00
|
|
|
let(:assignee) { create(:user) }
|
|
|
|
let(:milestone) { create(:milestone, project: project) }
|
2016-04-21 07:40:52 -04:00
|
|
|
let(:labels) { create_pair(:label, project: project) }
|
2016-04-21 06:46:48 -04:00
|
|
|
|
2014-04-02 06:38:35 -04:00
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
2016-02-15 13:13:52 -05:00
|
|
|
project.team << [assignee, :master]
|
2016-04-21 06:25:21 -04:00
|
|
|
end
|
2016-02-15 13:13:52 -05:00
|
|
|
|
2016-04-21 06:25:21 -04:00
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Awesome issue',
|
2016-02-15 13:13:52 -05:00
|
|
|
description: 'please fix',
|
2016-04-21 06:46:48 -04:00
|
|
|
assignee: assignee,
|
|
|
|
label_ids: labels.map(&:id),
|
|
|
|
milestone_id: milestone.id }
|
2014-04-02 06:38:35 -04:00
|
|
|
end
|
|
|
|
|
2016-04-21 06:25:21 -04:00
|
|
|
it { expect(issue).to be_valid }
|
|
|
|
it { expect(issue.title).to eq('Awesome issue') }
|
|
|
|
it { expect(issue.assignee).to eq assignee }
|
2016-04-21 06:46:48 -04:00
|
|
|
it { expect(issue.labels).to match_array labels }
|
|
|
|
it { expect(issue.milestone).to eq milestone }
|
2016-02-15 13:13:52 -05:00
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
it 'creates a pending todo for new assignee' do
|
2016-02-15 13:13:52 -05:00
|
|
|
attributes = {
|
|
|
|
project: project,
|
|
|
|
author: user,
|
|
|
|
user: assignee,
|
2016-04-21 06:25:21 -04:00
|
|
|
target_id: issue.id,
|
|
|
|
target_type: issue.class.name,
|
2016-02-20 08:59:59 -05:00
|
|
|
action: Todo::ASSIGNED,
|
2016-02-15 13:13:52 -05:00
|
|
|
state: :pending
|
|
|
|
}
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
expect(Todo.where(attributes).count).to eq 1
|
2016-02-15 13:13:52 -05:00
|
|
|
end
|
2016-04-21 06:20:05 -04:00
|
|
|
|
2016-04-21 07:40:52 -04:00
|
|
|
context 'when label belongs to different project' do
|
2016-04-21 06:20:05 -04:00
|
|
|
let(:label) { create(:label) }
|
2016-04-21 06:25:21 -04:00
|
|
|
|
2016-04-21 06:20:05 -04:00
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
label_ids: [label.id] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not assign label'do
|
|
|
|
expect(issue.labels).to_not include label
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-21 07:40:52 -04:00
|
|
|
context 'when milestone belongs to different project' do
|
2016-04-21 06:20:05 -04:00
|
|
|
let(:milestone) { create(:milestone) }
|
2016-04-21 06:25:21 -04:00
|
|
|
|
2016-04-21 06:20:05 -04:00
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
milestone_id: milestone.id }
|
|
|
|
end
|
|
|
|
|
2016-04-21 06:25:21 -04:00
|
|
|
it 'does not assign milestone' do
|
2016-04-21 06:20:05 -04:00
|
|
|
expect(issue.milestone).to_not eq milestone
|
|
|
|
end
|
|
|
|
end
|
2014-04-02 06:38:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|