@@ -252,7 +252,7 @@ def name_and_order(enum)
252252 end
253253
254254 def children_name_and_order
255- name_and_order ( @parent . children ( reload = true ) )
255+ name_and_order ( @parent . children . reload )
256256 end
257257
258258 def roots_name_and_order
@@ -454,7 +454,7 @@ def roots_name_and_order
454454 it 'should retain sort orders of descendants when moving to a new parent' do
455455 expected_order = ( 'a' ..'z' ) . to_a . shuffle
456456 expected_order . map { |ea | first_root . add_child ( Label . new ( name : ea ) ) }
457- actual_order = first_root . children ( reload = true ) . pluck ( :name )
457+ actual_order = first_root . children . reload . pluck ( :name )
458458 expect ( actual_order ) . to eq ( expected_order )
459459 last_root . append_child ( first_root )
460460 expect ( last_root . self_and_descendants . pluck ( :name ) ) . to eq ( %w( 10 0 ) + expected_order )
@@ -465,13 +465,13 @@ def roots_name_and_order
465465 z = first_root . find_or_create_by_path ( path )
466466 z_children_names = ( 100 ..150 ) . to_a . shuffle . map { |ea | ea . to_s }
467467 z_children_names . reverse . each { |ea | z . prepend_child ( Label . new ( name : ea ) ) }
468- expect ( z . children ( reload = true ) . pluck ( :name ) ) . to eq ( z_children_names )
468+ expect ( z . children . reload . pluck ( :name ) ) . to eq ( z_children_names )
469469 a = first_root . find_by_path ( [ 'a' ] )
470470 # move b up to a's level:
471471 b = a . children . first
472472 a . add_sibling ( b )
473473 expect ( b . parent ) . to eq ( first_root )
474- expect ( z . children ( reload = true ) . pluck ( :name ) ) . to eq ( z_children_names )
474+ expect ( z . children . reload . pluck ( :name ) ) . to eq ( z_children_names )
475475 end
476476 end
477477
@@ -524,4 +524,31 @@ def roots_name_and_order
524524 expect ( Label . roots_and_descendants_preordered . collect { |ea | ea . name } ) . to eq ( expected )
525525 end
526526 end unless sqlite? # sqlite doesn't have a power function.
527+
528+ context 'hash_tree' do
529+ before do
530+ @a = EventLabel . create ( name : 'a' )
531+ @b = DateLabel . create ( name : 'b' )
532+ @c = DirectoryLabel . create ( name : 'c' )
533+ ( 1 ..3 ) . each { |i | DirectoryLabel . create! ( name : "c#{ i } " , mother_id : @c . id ) }
534+ end
535+ it 'should return tree with correct scope when called on class' do
536+ tree = DirectoryLabel . hash_tree
537+ expect ( tree . keys . size ) . to eq ( 1 )
538+ expect ( tree . keys . first ) . to eq ( @c )
539+ expect ( tree [ @c ] . keys . size ) . to eq ( 3 )
540+ end
541+ it 'should return tree with correct scope when called on all' do
542+ tree = DirectoryLabel . all . hash_tree
543+ expect ( tree . keys . size ) . to eq ( 1 )
544+ expect ( tree . keys . first ) . to eq ( @c )
545+ expect ( tree [ @c ] . keys . size ) . to eq ( 3 )
546+ end
547+ it 'should return tree with correct scope when called on scope chain' do
548+ tree = Label . where ( name : 'b' ) . hash_tree
549+ expect ( tree . keys . size ) . to eq ( 1 )
550+ expect ( tree . keys . first ) . to eq ( @b )
551+ expect ( tree [ @b ] ) . to eq ( { } )
552+ end
553+ end
527554end
0 commit comments