@@ -19,7 +19,7 @@ def create_label_tree
19
19
Label . update_all ( "sort_order = id" )
20
20
end
21
21
22
- def create_preorder_tree
22
+ def create_preorder_tree ( suffix = "" )
23
23
%w(
24
24
a/l/n/r
25
25
a/l/n/q
@@ -30,16 +30,18 @@ def create_preorder_tree
30
30
a/b/c/d/g
31
31
a/b/c/d/f
32
32
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
40
41
ea . save!
41
42
end
42
43
end
44
+ end
43
45
end
44
46
45
47
describe Label do
@@ -344,6 +346,11 @@ def create_preorder_tree
344
346
expected = ( 'a' ..'r' ) . to_a
345
347
a . self_and_descendants_preordered . collect { |ea | ea . name } . should == expected
346
348
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
347
354
end
348
355
end unless ENV [ "DB" ] == "sqlite"
349
356
end
0 commit comments