2017-02-08 10:02:25 -05:00
|
|
|
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
|
2018-07-11 10:36:08 -04:00
|
|
|
member1 = group.add_maintainer(user1)
|
|
|
|
member2 = group.add_maintainer(user2)
|
|
|
|
member3 = group.add_maintainer(user3)
|
2017-02-08 10:02:25 -05:00
|
|
|
|
|
|
|
result = described_class.new(group).execute
|
|
|
|
|
2017-08-15 06:27:37 -04:00
|
|
|
expect(result.to_a).to match_array([member3, member2, member1])
|
2017-02-08 10:02:25 -05:00
|
|
|
end
|
|
|
|
|
2019-07-24 05:20:54 -04:00
|
|
|
it 'returns members for nested group' do
|
2018-12-06 08:15:29 -05:00
|
|
|
group.add_developer(user2)
|
2017-02-08 10:02:25 -05:00
|
|
|
nested_group.request_access(user4)
|
2018-07-11 10:36:08 -04:00
|
|
|
member1 = group.add_maintainer(user1)
|
|
|
|
member3 = nested_group.add_maintainer(user2)
|
|
|
|
member4 = nested_group.add_maintainer(user3)
|
2017-02-08 10:02:25 -05:00
|
|
|
|
|
|
|
result = described_class.new(nested_group).execute
|
|
|
|
|
2017-08-15 06:27:37 -04:00
|
|
|
expect(result.to_a).to match_array([member1, member3, member4])
|
2017-02-08 10:02:25 -05:00
|
|
|
end
|
2018-06-07 16:54:24 -04:00
|
|
|
|
2019-07-24 05:20:54 -04:00
|
|
|
it 'returns members for descendant groups if requested' do
|
2018-07-11 10:36:08 -04:00
|
|
|
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)
|
2018-06-07 16:54:24 -04:00
|
|
|
|
|
|
|
result = described_class.new(group).execute(include_descendants: true)
|
|
|
|
|
|
|
|
expect(result.to_a).to match_array([member1, member2, member3, member4])
|
|
|
|
end
|
2017-02-08 10:02:25 -05:00
|
|
|
end
|