File: update_boards_shared_examples.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (83 lines) | stat: -rw-r--r-- 2,446 bytes parent folder | download
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true

RSpec.shared_examples 'board update service' do
  subject(:service) { described_class.new(board.resource_parent, user, all_params) }

  it 'updates the board with valid params' do
    result = described_class.new(group, user, name: 'Engineering').execute(board)

    expect(result).to eq(true)
    expect(board.reload.name).to eq('Engineering')
  end

  it 'does not update the board with invalid params' do
    orig_name = board.name

    result = described_class.new(group, user, name: nil).execute(board)

    expect(result).to eq(false)
    expect(board.reload.name).to eq(orig_name)
  end

  context 'with scoped_issue_board available' do
    before do
      stub_licensed_features(scoped_issue_board: true)
    end

    context 'user is member of the board parent' do
      before do
        board.resource_parent.add_reporter(user)
      end

      it 'updates the configuration params when scoped issue board is enabled' do
        service.execute(board)

        labels = updated_scoped_params.delete(:labels)
        expect(board.reload).to have_attributes(updated_scoped_params)
        expect(board.labels).to match_array(labels)
      end
    end

    context 'when labels param is used' do
      let(:params) { { labels: [label.name, parent_label.name, 'new label'].join(',') } }

      subject(:service) { described_class.new(board.resource_parent, user, params) }

      context 'when user can create new labels' do
        before do
          board.resource_parent.add_reporter(user)
        end

        it 'adds labels to the board' do
          service.execute(board)

          expect(board.reload.labels.map(&:name)).to match_array([label.name, parent_label.name, 'new label'])
        end
      end

      context 'when user can not create new labels' do
        before do
          board.resource_parent.add_guest(user)
        end

        it 'adds only existing labels to the board' do
          service.execute(board)

          expect(board.reload.labels.map(&:name)).to match_array([label.name, parent_label.name])
        end
      end
    end
  end

  context 'without scoped_issue_board available' do
    before do
      stub_licensed_features(scoped_issue_board: false)
    end

    it 'filters unpermitted params when scoped issue board is not enabled' do
      service.execute(board)

      expect(board.reload).to have_attributes(updated_without_scoped_params)
    end
  end
end