From 8aac533614cb38bfe77b3141b0212c52de9c67a5 Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Sun, 3 Apr 2005 06:11:37 +0000 Subject: [PATCH] orphaned_pages considers self-linking pages as orphans --- app/models/page_set.rb | 12 ++++++++++-- test/unit/web_test.rb | 26 ++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/app/models/page_set.rb b/app/models/page_set.rb index 1e0d994e..5b298ea6 100644 --- a/app/models/page_set.rb +++ b/app/models/page_set.rb @@ -55,9 +55,17 @@ class PageSet < Array # pages in this set for which there is no reference in the web. # The HomePage and author pages are always assumed to have # references and so cannot be orphans + # Pages that refer to themselves and have no links from outside are oprphans. def orphaned_pages - references = web.select.wiki_words + ['HomePage'] + web.select.authors - self.reject { |page| references.include?(page.name) } + never_orphans = web.select.authors + ['HomePage'] + self.select { |page| + if never_orphans.include? page.name + false + else + references = pages_that_reference(page.name) + references.empty? or references == [page] + end + } end # Returns all the wiki words in this page set for which diff --git a/test/unit/web_test.rb b/test/unit/web_test.rb index e9cdb52f..1101a5fa 100755 --- a/test/unit/web_test.rb +++ b/test/unit/web_test.rb @@ -139,12 +139,30 @@ class WebTest < Test::Unit::TestCase assert_equal [home], @web.select.pages_that_link_to('AnotherPage') 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 def add_sample_pages - @web.add_page(Page.new(@web, 'EverBeenInLove', 'Who am I me', - Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')) - @web.add_page(Page.new(@web, 'EverBeenHated', 'I am me EverBeenHated', - Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson')) + @in_love = @web.add_page(Page.new(@web, 'EverBeenInLove', 'Who am I me', + Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')) + @hated = @web.add_page(Page.new(@web, 'EverBeenHated', 'I am me EverBeenHated', + Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson')) end end