group_members_finder_spec.rb 1.46 KB
Newer Older
1
2
# frozen_string_literal: true

3
4
5
6
7
8
9
10
11
12
13
require 'spec_helper'

describe GroupMembersFinder, '#execute' do
  let(:group)        { create(:group) }
  let(:nested_group) { create(:group, :access_requestable, parent: group) }
  let(:user1)        { create(:user) }
  let(:user2)        { create(:user) }
  let(:user3)        { create(:user) }
  let(:user4)        { create(:user) }

  it 'returns members for top-level group' do
14
15
16
    member1 = group.add_maintainer(user1)
    member2 = group.add_maintainer(user2)
    member3 = group.add_maintainer(user3)
17
18
19

    result = described_class.new(group).execute

20
    expect(result.to_a).to match_array([member3, member2, member1])
21
22
  end

23
  it 'returns members for nested group' do
24
    group.add_developer(user2)
25
    nested_group.request_access(user4)
26
27
28
    member1 = group.add_maintainer(user1)
    member3 = nested_group.add_maintainer(user2)
    member4 = nested_group.add_maintainer(user3)
29
30
31

    result = described_class.new(nested_group).execute

32
    expect(result.to_a).to match_array([member1, member3, member4])
33
  end
34

35
  it 'returns members for descendant groups if requested' do
36
37
38
39
40
    member1 = group.add_maintainer(user2)
    member2 = group.add_maintainer(user1)
    nested_group.add_maintainer(user2)
    member3 = nested_group.add_maintainer(user3)
    member4 = nested_group.add_maintainer(user4)
41
42
43
44
45

    result = described_class.new(group).execute(include_descendants: true)

    expect(result.to_a).to match_array([member1, member2, member3, member4])
  end
46
end