Skip to content

Commit 36c646e

Browse files
committed
add multiple roots for roots_and_descendants_preordered test
1 parent 26be658 commit 36c646e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

spec/label_spec.rb

+15-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def create_label_tree
1919
Label.update_all("sort_order = id")
2020
end
2121

22-
def create_preorder_tree
22+
def create_preorder_tree(suffix = "")
2323
%w(
2424
a/l/n/r
2525
a/l/n/q
@@ -30,16 +30,18 @@ def create_preorder_tree
3030
a/b/c/d/g
3131
a/b/c/d/f
3232
a/b/c/d/e
33-
).shuffle.each { |ea| Label.find_or_create_by_path(ea.split '/') }
34-
a = Label.find_by_path(["a"])
35-
a.order_value = 0
36-
a.save!
37-
a.self_and_descendants.each do |ea|
38-
ea.children.to_a.sort_by(&:name).each_with_index do |ea, idx|
39-
ea.order_value = idx
33+
).shuffle.each { |ea| Label.find_or_create_by_path(ea.split('/').collect { |ea| "#{ea}#{suffix}" }) }
34+
35+
Label.roots.each_with_index do |root, root_idx|
36+
root.order_value = root_idx
37+
root.save!
38+
root.self_and_descendants.each do |ea|
39+
ea.children.to_a.sort_by(&:name).each_with_index do |ea, idx|
40+
ea.order_value = idx
4041
ea.save!
4142
end
4243
end
44+
end
4345
end
4446

4547
describe Label do
@@ -344,6 +346,11 @@ def create_preorder_tree
344346
expected = ('a'..'r').to_a
345347
a.self_and_descendants_preordered.collect { |ea| ea.name }.should == expected
346348
Label.roots_and_descendants_preordered.collect { |ea| ea.name }.should == expected
349+
create_preorder_tree("1")
350+
# Should be no change:
351+
a.reload.self_and_descendants_preordered.collect { |ea| ea.name }.should == expected
352+
expected += ('a'..'r').collect { |ea| "#{ea}1" }
353+
Label.roots_and_descendants_preordered.collect { |ea| ea.name }.should == expected
347354
end
348355
end unless ENV["DB"] == "sqlite"
349356
end

0 commit comments

Comments
 (0)