summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorHeinrich Lee Yu <heinrich@gitlab.com>2019-03-21 09:09:47 +0800
committerHeinrich Lee Yu <heinrich@gitlab.com>2019-04-05 07:56:21 +0800
commitb752b579e9c84382002fe47c08282338fc3299d4 (patch)
treee0955b1e898866b7f339bfd6d9b5e2986b04a4e6 /spec/lib
parent3ccb4d954f4c51f4f3cc77ebd53f21425e0d4d09 (diff)
downloadgitlab-ce-b752b579e9c84382002fe47c08282338fc3299d4.tar.gz
Adds max_descendants_depth to ObjectHierarchy
CE-port of 10546-fix-epic-depth-validation
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/object_hierarchy_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/lib/gitlab/object_hierarchy_spec.rb b/spec/lib/gitlab/object_hierarchy_spec.rb
index 4700a7ad2e1..e6e9ae3223e 100644
--- a/spec/lib/gitlab/object_hierarchy_spec.rb
+++ b/spec/lib/gitlab/object_hierarchy_spec.rb
@@ -81,6 +81,24 @@ describe Gitlab::ObjectHierarchy, :postgresql do
expect { relation.update_all(share_with_group_lock: false) }
.to raise_error(ActiveRecord::ReadOnlyRecord)
end
+
+ context 'when with_depth is true' do
+ let(:relation) do
+ described_class.new(Group.where(id: parent.id)).base_and_descendants(with_depth: true)
+ end
+
+ it 'includes depth in the results' do
+ object_depths = {
+ parent.id => 1,
+ child1.id => 2,
+ child2.id => 3
+ }
+
+ relation.each do |object|
+ expect(object.depth).to eq(object_depths[object.id])
+ end
+ end
+ end
end
describe '#descendants' do
@@ -91,6 +109,28 @@ describe Gitlab::ObjectHierarchy, :postgresql do
end
end
+ describe '#max_descendants_depth' do
+ subject { described_class.new(base_relation).max_descendants_depth }
+
+ context 'when base relation is empty' do
+ let(:base_relation) { Group.where(id: nil) }
+
+ it { expect(subject).to be_nil }
+ end
+
+ context 'when base has no children' do
+ let(:base_relation) { Group.where(id: child2) }
+
+ it { expect(subject).to eq(1) }
+ end
+
+ context 'when base has grandchildren' do
+ let(:base_relation) { Group.where(id: parent) }
+
+ it { expect(subject).to eq(3) }
+ end
+ end
+
describe '#ancestors' do
it 'includes only the ancestors' do
relation = described_class.new(Group.where(id: child2)).ancestors