Commit 85bcc222 authored by Valerie Burton's avatar Valerie Burton

Use traversal_ids instead of path for ordering

parent fcc24a29
......@@ -2,14 +2,14 @@
RSpec.shared_examples 'namespace traversal scopes' do
# Hierarchy 1
let_it_be(:group_1) { create(:group, path: 'group-1') }
let_it_be(:nested_group_1) { create(:group, path: 'nested-group-1', parent: group_1) }
let_it_be(:deep_nested_group_1) { create(:group, path: 'deep-nested-group-1', parent: nested_group_1) }
let_it_be(:group_1) { create(:group) }
let_it_be(:nested_group_1) { create(:group, parent: group_1) }
let_it_be(:deep_nested_group_1) { create(:group, parent: nested_group_1) }
# Hierarchy 2
let_it_be(:group_2) { create(:group, path: 'group-2') }
let_it_be(:nested_group_2) { create(:group, path: 'nested-group-2', parent: group_2) }
let_it_be(:deep_nested_group_2) { create(:group, path: 'deep-nested-group-2', parent: nested_group_2) }
let_it_be(:group_2) { create(:group) }
let_it_be(:nested_group_2) { create(:group, parent: group_2) }
let_it_be(:deep_nested_group_2) { create(:group, parent: nested_group_2) }
# All groups
let_it_be(:groups) do
......@@ -126,7 +126,12 @@ RSpec.shared_examples 'namespace traversal scopes' do
end
context 'with offset and limit' do
subject { described_class.where(id: [deep_nested_group_1, deep_nested_group_2]).order(:path).offset(1).limit(1).self_and_ancestors }
subject { described_class.where(id: [deep_nested_group_1, deep_nested_group_2]).order(:traversal_ids).offset(1).limit(1).self_and_ancestors }
before do
deep_nested_group_1.reload
deep_nested_group_2.reload
end
it { is_expected.to contain_exactly(group_2, nested_group_2, deep_nested_group_2) }
end
......@@ -185,13 +190,18 @@ RSpec.shared_examples 'namespace traversal scopes' do
subject do
described_class
.where(id: [deep_nested_group_1, deep_nested_group_2])
.order(:path)
.order(:traversal_ids)
.limit(1)
.offset(1)
.self_and_ancestor_ids
.pluck(:id)
end
before do
deep_nested_group_1.reload
deep_nested_group_2.reload
end
it { is_expected.to contain_exactly(group_2.id, nested_group_2.id, deep_nested_group_2.id) }
end
end
......@@ -241,7 +251,12 @@ RSpec.shared_examples 'namespace traversal scopes' do
end
context 'with offset and limit' do
subject { described_class.where(id: [group_1, group_2]).order(:path).offset(1).limit(1).self_and_descendants }
subject { described_class.where(id: [group_1, group_2]).order(:traversal_ids).offset(1).limit(1).self_and_descendants }
before do
group_1.reload
group_2.reload
end
it { is_expected.to contain_exactly(group_2, nested_group_2, deep_nested_group_2) }
end
......@@ -289,13 +304,18 @@ RSpec.shared_examples 'namespace traversal scopes' do
subject do
described_class
.where(id: [group_1, group_2])
.order(:path)
.order(:traversal_ids)
.limit(1)
.offset(1)
.self_and_descendant_ids
.pluck(:id)
end
before do
group_1.reload
group_2.reload
end
it { is_expected.to contain_exactly(group_2.id, nested_group_2.id, deep_nested_group_2.id) }
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment