diff --git a/app/models/page_set.rb b/app/models/page_set.rb index aef3ff4d..f8e84df4 100644 --- a/app/models/page_set.rb +++ b/app/models/page_set.rb @@ -83,12 +83,17 @@ class PageSet < Array # Returns all the wiki words in this page set for which # there are no pages in this page set's web def wanted_pages - wiki_words - web.select.names + known_pages = (web.select.names + redirected_names).uniq + wiki_words - known_pages end def names self.map { |page| page.name } end + + def redirected_names + self.wiki_words.select {|name| web.has_redirect_for?(name) }.uniq.sort + end def wiki_words self.inject([]) { |wiki_words, page| diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb index 395d4466..08dd4b1e 100644 --- a/test/unit/page_test.rb +++ b/test/unit/page_test.rb @@ -136,6 +136,8 @@ class PageTest < ActiveSupport::TestCase assert_equal WikiReference::WANTED_PAGE, references[0].link_type assert_equal 'WantedPage2', references[1].referenced_name assert_equal WikiReference::WANTED_PAGE, references[1].link_type + wanted_pages = web.select.wanted_pages + assert_equal ["HappyPage", "HisWay", "OverThere", "WantedPage2"], wanted_pages my_page = Page.new(:web => web, :name => 'MyPage') my_page.revise("[[!redirects HappyPage]]\nAnd here it is!", 'MyPage', Time.now, 'AlexeyVerkhovsky', test_renderer) @@ -143,10 +145,12 @@ class PageTest < ActiveSupport::TestCase assert_equal 1, my_references.size assert_equal 'HappyPage', my_references[0].referenced_name assert_equal WikiReference::REDIRECTED_PAGE, my_references[0].link_type + wanted_pages = web.select.wanted_pages + assert_equal ["HisWay", "OverThere", "WantedPage2"], wanted_pages # link type stored for NewPage -> HappyPage reference should change from WANTED to LINKED # reference NewPage -> WantedPage2 should remain the same - references = new_page.wiki_references(true) + references = new_page.wiki_references #(true) assert_match( "Reference to Happy Page", test_renderer(new_page.revisions.last).display_content(true) ) assert_equal 2, references.size @@ -155,6 +159,8 @@ class PageTest < ActiveSupport::TestCase # assert_equal WikiReference::LINKED_PAGE, references[0].link_type assert_equal 'WantedPage2', references[1].referenced_name assert_equal WikiReference::WANTED_PAGE, references[1].link_type + wanted_pages = web.select.wanted_pages + assert_equal ["HisWay", "OverThere", "WantedPage2"], wanted_pages new_page.revise('Reference to HappyPage and to WantedPage2.pdf and [[foo.pdf]]', 'NewPage', Time.now, 'AlexeyVerkhovsky', test_renderer) @@ -171,6 +177,8 @@ class PageTest < ActiveSupport::TestCase assert_equal WikiReference::WANTED_PAGE, references[1].link_type assert_equal 'foo.pdf', references[2].referenced_name assert_equal WikiReference::WANTED_PAGE, references[1].link_type + wanted_pages = web.select.wanted_pages + assert_equal ["HisWay", "OverThere", "WantedPage2"], wanted_pages end def test_rollback