diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-04 16:13:16 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-04 22:49:42 +0200 |
commit | 08383fd2e32b88bba1429cf9b03b493dfc6b9b3e (patch) | |
tree | cb46a2cb6d8ff2cc6efab9865c59491ee15c586c /spec | |
parent | de55396134e9e3de429c5c6df55ff06efb8ba329 (diff) | |
download | gitlab-ce-08383fd2e32b88bba1429cf9b03b493dfc6b9b3e.tar.gz |
Make it possible to limit ancestors in a `GroupHierarchy`
Passing a parent_id will limit ancestors upto the specified parent if
it is found.
Using `ancestors` and `descendants` the `base` relation will not be included
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/group_hierarchy_spec.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/lib/gitlab/group_hierarchy_spec.rb b/spec/lib/gitlab/group_hierarchy_spec.rb index 8dc83a6db7f..30686634af4 100644 --- a/spec/lib/gitlab/group_hierarchy_spec.rb +++ b/spec/lib/gitlab/group_hierarchy_spec.rb @@ -18,6 +18,12 @@ describe Gitlab::GroupHierarchy, :postgresql do expect(relation).to include(parent, child1) end + it 'can find ancestors upto a certain level' do + relation = described_class.new(Group.where(id: child2)).base_and_ancestors(upto: child1) + + expect(relation).to contain_exactly(child2) + end + it 'uses ancestors_base #initialize argument' do relation = described_class.new(Group.where(id: child2.id), Group.none).base_and_ancestors @@ -55,6 +61,28 @@ describe Gitlab::GroupHierarchy, :postgresql do end end + describe '#descendants' do + it 'includes only the descendants' do + relation = described_class.new(Group.where(id: parent)).descendants + + expect(relation).to contain_exactly(child1, child2) + end + end + + describe '#ancestors' do + it 'includes only the ancestors' do + relation = described_class.new(Group.where(id: child2)).ancestors + + expect(relation).to contain_exactly(child1, parent) + end + + it 'can find ancestors upto a certain level' do + relation = described_class.new(Group.where(id: child2)).ancestors(upto: child1) + + expect(relation).to be_empty + end + end + describe '#all_groups' do let(:relation) do described_class.new(Group.where(id: child1.id)).all_groups |