Skip to content

Commit b45f747

Browse files
committed
Fix chained inclusion ancestors_of
Fixes #814 Signed-off-by: Ulysse Buonomo <buonomo.ulysse@gmail.com>
1 parent 59e4cc0 commit b45f747

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lib/rdoc/ri/driver.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,11 +609,11 @@ def ancestors_of klass
609609

610610
stores = classes[current]
611611

612-
break unless stores and not stores.empty?
612+
next unless stores and not stores.empty?
613613

614-
klasses = stores.map do |store|
615-
store.ancestors[current]
616-
end.flatten.uniq
614+
klasses = stores.flat_map do |store|
615+
store.ancestors[current] || []
616+
end.uniq
617617

618618
klasses = klasses - seen
619619

test/rdoc/test_rdoc_ri_driver.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,30 @@ def test_ancestors_of
421421
assert_equal %w[X Mixin Object Foo], @driver.ancestors_of('Foo::Bar')
422422
end
423423

424+
def test_ancestors_of_chained_inclusion
425+
# Store represents something like:
426+
#
427+
# module X
428+
# end
429+
#
430+
# module Y
431+
# include X
432+
# end
433+
#
434+
# class Z
435+
# include Y
436+
# end
437+
#
438+
# Y is not chosen randomly, it has to be after Object in the alphabet
439+
# to reproduce https://github.com/ruby/rdoc/issues/814.
440+
store = RDoc::RI::Store.new @home_ri
441+
store.cache[:ancestors] = { "Z" => ["Object", "Y"], "Y" => ["X"] }
442+
store.cache[:modules] = %W[X Y Z]
443+
@driver.stores = [store]
444+
445+
assert_equal %w[X Y Object], @driver.ancestors_of('Z')
446+
end
447+
424448
def test_classes
425449
util_multi_store
426450

0 commit comments

Comments
 (0)