summaryrefslogtreecommitdiff
path: root/spec/services/issues/create_service_spec.rb
blob: f3b6677998799f3bf531ff6aa909b701f30f913e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'spec_helper'

describe Issues::CreateService, services: true do
  let(:project) { create(:empty_project) }
  let(:user) { create(:user) }
  let(:assignee) { create(:user) }

  describe :execute do
    context 'valid params' do
      before do
        project.team << [user, :master]
        project.team << [assignee, :master]

        opts = {
          title: 'Awesome issue',
          description: 'please fix',
          assignee: assignee
        }

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

      it { expect(@issue).to be_valid }
      it { expect(@issue.title).to eq('Awesome issue') }
      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
    end
  end
end