From 6ff74f6b5acbaa2e16ba340653f1ee5fd5c3d423 Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Sun, 11 Sep 2005 06:15:59 +0000 Subject: [PATCH] Update wiki_references to a newly created page from 'W' to 'L' --- app/models/page.rb | 4 ++++ test/unit/page_renderer_test.rb | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/models/page.rb b/app/models/page.rb index 715ac6ce..44d76102 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -4,6 +4,10 @@ class Page < ActiveRecord::Base has_many :wiki_references, :order => 'referenced_page_name' has_one :current_revision, :class_name => 'Revision', :order => 'id DESC' + def before_create + WikiReference.register_page_creation(self) + end + def revise(content, time, author, renderer) revisions_size = new_record? ? 0 : revisions.size if (revisions_size > 0) and content == current_revision.content diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb index 0a555e34..c8bbeb92 100644 --- a/test/unit/page_renderer_test.rb +++ b/test/unit/page_renderer_test.rb @@ -340,6 +340,27 @@ class PageRendererTest < Test::Unit::TestCase end def test_rendering_changes_references_from_wanted_to_linked + new_page = @web.add_page('NewPage', 'Reference to WantedPage, and to WantedPage2', + Time.now, 'AlexeyVerkhovsky', test_renderer) + + references = new_page.wiki_references(true) + assert_equal 2, references.size + assert_equal 'WantedPage', references[0].referenced_page_name + assert_equal WikiReference::WANTED_PAGE, references[0].link_type + assert_equal 'WantedPage2', references[1].referenced_page_name + assert_equal WikiReference::WANTED_PAGE, references[1].link_type + + wanted_page = @web.add_page('WantedPage', 'And here it is!', + Time.now, 'AlexeyVerkhovsky', test_renderer) + + # link type stored for NewPage -> WantedPage reference should change from WANTED to LINKED + # reference NewPage -> WantedPage2 should remain the same + references = new_page.wiki_references(true) + assert_equal 2, references.size + assert_equal 'WantedPage', references[0].referenced_page_name + assert_equal WikiReference::LINKED_PAGE, references[0].link_type + assert_equal 'WantedPage2', references[1].referenced_page_name + assert_equal WikiReference::WANTED_PAGE, references[1].link_type end private