summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/boards/lists/update_service_shared_examples.rb
blob: 1fab31cd51338dba23d14d06faf8020a66b429f6 (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
# frozen_string_literal: true

RSpec.shared_examples 'moving list' do
  context 'when user can admin list' do
    before do
      board.resource_parent.add_developer(user)
    end

    context 'when the new position is valid' do
      it 'calls Lists::MoveService to update list position' do
        expect_next_instance_of(Boards::Lists::MoveService, board.resource_parent, user, params) do |move_service|
          expect(move_service).to receive(:execute).with(list).and_call_original
        end

        service.execute(list)
      end

      it 'returns a success response' do
        expect(service.execute(list)).to be_success
      end
    end

    context 'when the new position is invalid' do
      let(:params) { { position: 10 } }

      it 'returns error response' do
        expect(service.execute(list)).to be_error
      end
    end
  end

  context 'when user cannot admin list' do
    it 'does not call Lists::MoveService to update list position' do
      expect(Boards::Lists::MoveService).not_to receive(:new)

      service.execute(list)
    end

    it 'returns an error response' do
      expect(service.execute(list)).to be_error
    end
  end
end

RSpec.shared_examples 'updating list preferences' do
  context 'when user can read list' do
    it 'updates list preference for user' do
      board.resource_parent.add_guest(user)

      service.execute(list)

      expect(list.preferences_for(user).collapsed).to eq(true)
    end
  end

  context 'when user cannot read list' do
    it 'does not update list preference for user' do
      service.execute(list)

      expect(list.preferences_for(user).collapsed).to be_falsy
    end
  end
end