2016-03-01 15:22:29 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe GroupsFinder do
|
|
|
|
describe '#execute' do
|
2016-03-18 12:28:16 +00:00
|
|
|
let(:user) { create(:user) }
|
2016-03-01 15:22:29 +00:00
|
|
|
|
2017-05-03 23:51:25 +00:00
|
|
|
context 'root level groups' do
|
|
|
|
let!(:private_group) { create(:group, :private) }
|
|
|
|
let!(:internal_group) { create(:group, :internal) }
|
|
|
|
let!(:public_group) { create(:group, :public) }
|
|
|
|
|
|
|
|
context 'without a user' do
|
|
|
|
subject { described_class.new.execute }
|
2016-03-01 15:22:29 +00:00
|
|
|
|
|
|
|
it { is_expected.to eq([public_group]) }
|
|
|
|
end
|
|
|
|
|
2017-05-03 23:51:25 +00:00
|
|
|
context 'with a user' do
|
|
|
|
subject { described_class.new(user).execute }
|
2016-03-01 15:22:29 +00:00
|
|
|
|
2016-03-17 22:42:46 +00:00
|
|
|
context 'normal user' do
|
2017-05-03 23:51:25 +00:00
|
|
|
it { is_expected.to contain_exactly(public_group, internal_group) }
|
2016-03-17 22:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'external user' do
|
2016-03-18 12:28:16 +00:00
|
|
|
let(:user) { create(:user, external: true) }
|
|
|
|
|
2017-05-03 23:51:25 +00:00
|
|
|
it { is_expected.to contain_exactly(public_group) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user is member of the private group' do
|
|
|
|
before do
|
|
|
|
private_group.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(public_group, internal_group, private_group) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'subgroups' do
|
|
|
|
let!(:parent_group) { create(:group, :public) }
|
|
|
|
let!(:public_subgroup) { create(:group, :public, parent: parent_group) }
|
|
|
|
let!(:internal_subgroup) { create(:group, :internal, parent: parent_group) }
|
|
|
|
let!(:private_subgroup) { create(:group, :private, parent: parent_group) }
|
|
|
|
|
|
|
|
context 'without a user' do
|
|
|
|
it 'only returns public subgroups' do
|
|
|
|
expect(described_class.new(nil, parent: parent_group).execute).to contain_exactly(public_subgroup)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a user' do
|
|
|
|
it 'returns public and internal subgroups' do
|
|
|
|
expect(described_class.new(user, parent: parent_group).execute).to contain_exactly(public_subgroup, internal_subgroup)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'being member' do
|
|
|
|
it 'returns public subgroups, internal subgroups, and private subgroups user is member of' do
|
|
|
|
private_subgroup.add_guest(user)
|
|
|
|
|
|
|
|
expect(described_class.new(user, parent: parent_group).execute).to contain_exactly(public_subgroup, internal_subgroup, private_subgroup)
|
|
|
|
end
|
2016-03-17 22:42:46 +00:00
|
|
|
end
|
2016-03-01 15:22:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|