summaryrefslogtreecommitdiff
path: root/spec/services/boards/lists/destroy_service_spec.rb
blob: 4d50bd2d12350cc4583cb7f69cd2cde3671c3630 (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
require 'spec_helper'

describe Boards::Lists::DestroyService, services: true do
  describe '#execute' do
    let(:project) { create(:project_with_board) }
    let(:board)   { project.board }

    context 'when list type is label' do
      it 'removes list from board' do
        list = create(:label_list, board: board)
        service = described_class.new(project, list_id: list.id)

        expect { service.execute }.to change(board.lists, :count).by(-1)
      end

      it 'decrements position of higher lists' do
        backlog     = create(:backlog_list, board: board)
        development = create(:label_list, board: board, position: 1)
        review      = create(:label_list, board: board, position: 2)
        staging     = create(:label_list, board: board, position: 3)
        done        = create(:done_list, board: board)

        described_class.new(project, list_id: development.id).execute

        expect(backlog.reload.position).to be_nil
        expect(review.reload.position).to eq 1
        expect(staging.reload.position).to eq 2
        expect(done.reload.position).to be_nil
      end
    end

    it 'does not remove list from board when list type is backlog' do
      list = create(:backlog_list, board: board)
      service = described_class.new(project, list_id: list.id)

      expect { service.execute }.not_to change(board.lists, :count)
    end

    it 'does not remove list from board when list type is done' do
      list = create(:done_list, board: board)
      service = described_class.new(project, list_id: list.id)

      expect { service.execute }.not_to change(board.lists, :count)
    end
  end
end