summaryrefslogtreecommitdiff
path: root/spec/services/boards/lists/create_service_spec.rb
blob: a7e9efcf93f41c2936d99b1c957708ce99d33482 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'spec_helper'

describe Boards::Lists::CreateService, services: true do
  describe '#execute' do
    let(:project) { create(:empty_project) }
    let(:board)   { create(:board, project: project) }
    let(:user)    { create(:user) }
    let(:label)   { create(:label, project: project, name: 'in-progress') }

    subject(:service) { described_class.new(project, user, label_id: label.id) }

    before do
      project.team << [user, :developer]
    end

    context 'when board lists is empty' do
      it 'creates a new list at beginning of the list' do
        list = service.execute(board)

        expect(list.position).to eq 0
      end
    end

    context 'when board lists has backlog, and done lists' do
      it 'creates a new list at beginning of the list' do
        list = service.execute(board)

        expect(list.position).to eq 0
      end
    end

    context 'when board lists has labels lists' do
      it 'creates a new list at end of the lists' do
        create(:list, board: board, position: 0)
        create(:list, board: board, position: 1)

        list = service.execute(board)

        expect(list.position).to eq 2
      end
    end

    context 'when board lists has backlog, label and done lists' do
      it 'creates a new list at end of the label lists' do
        list1 = create(:list, board: board, position: 0)

        list2 = service.execute(board)

        expect(list1.reload.position).to eq 0
        expect(list2.reload.position).to eq 1
      end
    end

    context 'when provided label does not belongs to the project' do
      it 'raises an error' do
        label = create(:label, name: 'in-development')
        service = described_class.new(project, user, label_id: label.id)

        expect { service.execute(board) }.to raise_error(ActiveRecord::RecordNotFound)
      end
    end
  end
end