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

78 lines
2.1 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-06-02 11:05:42 +05:30
assignee: assignee,
label_ids: labels.map(&:id),
milestone_id: milestone.id }
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
it { expect(issue).to be_valid }
it { expect(issue.title).to eq('Awesome issue') }
it { expect(issue.assignee).to eq assignee }
it { expect(issue.labels).to match_array labels }
it { expect(issue.milestone).to eq milestone }
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
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
2014-09-02 18:07:02 +05:30
end
end
end