summaryrefslogtreecommitdiff
path: root/spec/finders/move_to_project_finder_spec.rb
blob: 74639d4147f8e2b0bf63a12fdf5bc8224eddf210 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require 'spec_helper'

describe MoveToProjectFinder do
  let(:user) { create(:user) }
  let(:project) { create(:project) }

  let(:no_access_project) { create(:project) }
  let(:guest_project) { create(:project) }
  let(:reporter_project) { create(:project) }
  let(:developer_project) { create(:project) }
  let(:master_project) { create(:project) }

  subject { described_class.new(user) }

  describe '#execute' do
    context 'filter' do
      it 'does not return projects under Gitlab::Access::REPORTER' do
        guest_project.add_guest(user)

        expect(subject.execute(project)).to be_empty
      end

      it 'returns projects equal or above Gitlab::Access::REPORTER ordered by id in descending order' do
        reporter_project.add_reporter(user)
        developer_project.add_developer(user)
        master_project.add_master(user)

        expect(subject.execute(project).to_a).to eq([master_project, developer_project, reporter_project])
      end

      it 'does not include the source project' do
        project.add_reporter(user)

        expect(subject.execute(project).to_a).to be_empty
      end

      it 'does not return archived projects' do
        reporter_project.add_reporter(user)
        reporter_project.archive!
        other_reporter_project = create(:project)
        other_reporter_project.add_reporter(user)

        expect(subject.execute(project).to_a).to eq([other_reporter_project])
      end

      it 'does not return projects for which issues are disabled' do
        reporter_project.add_reporter(user)
        reporter_project.update_attributes(issues_enabled: false)
        other_reporter_project = create(:project)
        other_reporter_project.add_reporter(user)

        expect(subject.execute(project).to_a).to eq([other_reporter_project])
      end

      it 'returns a page of projects ordered by id in descending order' do
        stub_const 'MoveToProjectFinder::PAGE_SIZE', 2

        reporter_project.add_reporter(user)
        developer_project.add_developer(user)
        master_project.add_master(user)

        expect(subject.execute(project).to_a).to eq([master_project, developer_project])
      end

      it 'returns projects after the given offset id' do
        stub_const 'MoveToProjectFinder::PAGE_SIZE', 2

        reporter_project.add_reporter(user)
        developer_project.add_developer(user)
        master_project.add_master(user)

        expect(subject.execute(project, search: nil, offset_id: master_project.id).to_a).to eq([developer_project, reporter_project])
        expect(subject.execute(project, search: nil, offset_id: developer_project.id).to_a).to eq([reporter_project])
        expect(subject.execute(project, search: nil, offset_id: reporter_project.id).to_a).to be_empty
      end
    end

    context 'search' do
      it 'uses Project#search' do
        expect(user).to receive_message_chain(:projects_where_can_admin_issues, :search) { Project.all }

        subject.execute(project, search: 'wadus')
      end

      it 'returns projects matching a search query' do
        foo_project = create(:project)
        foo_project.add_master(user)

        wadus_project = create(:project, name: 'wadus')
        wadus_project.add_master(user)

        expect(subject.execute(project).to_a).to eq([wadus_project, foo_project])
        expect(subject.execute(project, search: 'wadus').to_a).to eq([wadus_project])
      end
    end
  end
end