orphaned_pages considers self-linking pages as orphans
This commit is contained in:
parent
b1e92e3719
commit
8aac533614
|
@ -55,9 +55,17 @@ class PageSet < Array
|
||||||
# pages in this set for which there is no reference in the web.
|
# pages in this set for which there is no reference in the web.
|
||||||
# The HomePage and author pages are always assumed to have
|
# The HomePage and author pages are always assumed to have
|
||||||
# references and so cannot be orphans
|
# references and so cannot be orphans
|
||||||
|
# Pages that refer to themselves and have no links from outside are oprphans.
|
||||||
def orphaned_pages
|
def orphaned_pages
|
||||||
references = web.select.wiki_words + ['HomePage'] + web.select.authors
|
never_orphans = web.select.authors + ['HomePage']
|
||||||
self.reject { |page| references.include?(page.name) }
|
self.select { |page|
|
||||||
|
if never_orphans.include? page.name
|
||||||
|
false
|
||||||
|
else
|
||||||
|
references = pages_that_reference(page.name)
|
||||||
|
references.empty? or references == [page]
|
||||||
|
end
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns all the wiki words in this page set for which
|
# Returns all the wiki words in this page set for which
|
||||||
|
|
|
@ -139,12 +139,30 @@ class WebTest < Test::Unit::TestCase
|
||||||
assert_equal [home], @web.select.pages_that_link_to('AnotherPage')
|
assert_equal [home], @web.select.pages_that_link_to('AnotherPage')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_orphaned_pages
|
||||||
|
add_sample_pages
|
||||||
|
home = @web.add_page(Page.new(@web, 'HomePage',
|
||||||
|
'This is a home page, it should not be an orphan',
|
||||||
|
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky'))
|
||||||
|
author = @web.add_page(Page.new(@web, 'AlexeyVerkhovsky',
|
||||||
|
'This is an author page, it should not be an orphan',
|
||||||
|
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky'))
|
||||||
|
self_linked = @web.add_page(Page.new(@web, 'SelfLinked',
|
||||||
|
'I am me SelfLinked and link to EverBeenInLove',
|
||||||
|
Time.local(2004, 4, 4, 16, 50), 'AnonymousCoward'))
|
||||||
|
|
||||||
|
# page that links to itself, and nobody else links to it must be an orphan
|
||||||
|
assert_equal ['EverBeenHated', 'SelfLinked'],
|
||||||
|
@web.select.orphaned_pages.collect{ |page| page.name }.sort
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def add_sample_pages
|
def add_sample_pages
|
||||||
@web.add_page(Page.new(@web, 'EverBeenInLove', 'Who am I me',
|
@in_love = @web.add_page(Page.new(@web, 'EverBeenInLove', 'Who am I me',
|
||||||
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson'))
|
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson'))
|
||||||
@web.add_page(Page.new(@web, 'EverBeenHated', 'I am me EverBeenHated',
|
@hated = @web.add_page(Page.new(@web, 'EverBeenHated', 'I am me EverBeenHated',
|
||||||
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson'))
|
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue