create_service_spec.rb 1.0 KB
Newer Older
1 2
require 'spec_helper'

D
Douwe Maan 已提交
3
describe Issues::CreateService, services: true do
4 5
  let(:project) { create(:empty_project) }
  let(:user) { create(:user) }
6
  let(:assignee) { create(:user) }
7 8

  describe :execute do
9
    context 'valid params' do
10 11
      before do
        project.team << [user, :master]
12 13
        project.team << [assignee, :master]

14 15
        opts = {
          title: 'Awesome issue',
16 17
          description: 'please fix',
          assignee: assignee
18 19 20 21 22
        }

        @issue = Issues::CreateService.new(project, user, opts).execute
      end

23 24
      it { expect(@issue).to be_valid }
      it { expect(@issue.title).to eq('Awesome issue') }
25 26 27 28 29 30 31 32 33 34 35 36 37 38
      it { expect(@issue.assignee).to eq assignee }

      it 'creates a pending task for new assignee' do
        attributes = {
          project: project,
          author: user,
          user: assignee,
          target: @issue,
          action: Task::ASSIGNED,
          state: :pending
        }

        expect(Task.where(attributes).count).to eq 1
      end
39 40 41
    end
  end
end