BigW Consortium Gitlab

issues_finder_spec.rb 3.46 KB
Newer Older
1 2
require 'spec_helper'

3
describe IssuesFinder do
4 5 6 7
  let(:user) { create :user }
  let(:user2) { create :user }
  let(:project1) { create(:project) }
  let(:project2) { create(:project) }
8
  let(:milestone) { create(:milestone, project: project1) }
9
  let(:label) { create(:label, project: project2) }
10 11 12
  let(:issue1) { create(:issue, author: user, assignee: user, project: project1, milestone: milestone) }
  let(:issue2) { create(:issue, author: user, assignee: user, project: project2) }
  let(:issue3) { create(:issue, author: user2, assignee: user2, project: project2) }
13
  let!(:label_link) { create(:label_link, label: label, target: issue2) }
14 15 16 17

  before do
    project1.team << [user, :master]
    project2.team << [user, :developer]
18
    project2.team << [user2, :developer]
19 20
  end

21
  describe :execute do
22 23 24 25 26 27
    before :each do
      issue1
      issue2
      issue3
    end

28 29 30
    context 'scope: all' do
      it 'should filter by all' do
        params = { scope: "all", state: 'opened' }
31
        issues = IssuesFinder.new(user, params).execute
32
        expect(issues.size).to eq(3)
33
      end
34

35 36
      it 'should filter by assignee id' do
        params = { scope: "all", assignee_id: user.id, state: 'opened' }
37
        issues = IssuesFinder.new(user, params).execute
38
        expect(issues.size).to eq(2)
39
      end
40

41 42
      it 'should filter by author id' do
        params = { scope: "all", author_id: user2.id, state: 'opened' }
43
        issues = IssuesFinder.new(user, params).execute
44
        expect(issues).to eq([issue3])
45
      end
46

47
      it 'should filter by milestone id' do
48
        params = { scope: "all", milestone_title: milestone.title, state: 'opened' }
49
        issues = IssuesFinder.new(user, params).execute
50
        expect(issues).to eq([issue1])
51 52
      end

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
      it 'should filter by no milestone id' do
        params = { scope: "all", milestone_title: Milestone::None.title, state: 'opened' }
        issues = IssuesFinder.new(user, params).execute
        expect(issues).to match_array([issue2, issue3])
      end

      it 'should filter by label name' do
        params = { scope: "all", label_name: label.title, state: 'opened' }
        issues = IssuesFinder.new(user, params).execute
        expect(issues).to eq([issue2])
      end

      it 'should filter by no label name' do
        params = { scope: "all", label_name: Label::None.title, state: 'opened' }
        issues = IssuesFinder.new(user, params).execute
        expect(issues).to match_array([issue1, issue3])
      end

71 72
      it 'should be empty for unauthorized user' do
        params = { scope: "all", state: 'opened' }
73
        issues = IssuesFinder.new(nil, params).execute
74
        expect(issues.size).to be_zero
75 76 77 78
      end

      it 'should not include unauthorized issues' do
        params = { scope: "all", state: 'opened' }
79
        issues = IssuesFinder.new(user2, params).execute
80 81 82 83
        expect(issues.size).to eq(2)
        expect(issues).not_to include(issue1)
        expect(issues).to include(issue2)
        expect(issues).to include(issue3)
84
      end
85 86
    end

87 88 89
    context 'personal scope' do
      it 'should filter by assignee' do
        params = { scope: "assigned-to-me", state: 'opened' }
90
        issues = IssuesFinder.new(user, params).execute
91
        expect(issues.size).to eq(2)
92 93 94 95
      end

      it 'should filter by project' do
        params = { scope: "assigned-to-me", state: 'opened', project_id: project1.id }
96
        issues = IssuesFinder.new(user, params).execute
97
        expect(issues.size).to eq(1)
98
      end
99
    end
100 101
  end
end