From b1e92e37194c7e1e6c210ecf1ebc730de27247fc Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Sun, 3 Apr 2005 05:15:56 +0000 Subject: [PATCH] Cache clearing in Revision did not include wiki_reference_cache, which caused new pages to be created as orphans --- app/models/revision.rb | 8 ++++---- app/models/web.rb | 13 +++++++------ test/unit/web_test.rb | 13 +++++++++++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/models/revision.rb b/app/models/revision.rb index 6277d326..248ae12a 100644 --- a/app/models/revision.rb +++ b/app/models/revision.rb @@ -54,12 +54,12 @@ class Revision # Returns an array of all the WikiWords present in the content of this revision. def wiki_words - unless @wiki_words_cache + unless @wiki_words_cache wiki_chunks = display_content.find_chunks(WikiChunk::WikiLink) @wiki_words_cache = wiki_chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq end @wiki_words_cache - end + end # Returns an array of all the WikiWords present in the content of this revision. # that already exists as a page in the web. @@ -88,8 +88,8 @@ class Revision end def clear_display_cache - @wiki_references_cache = @published_cache = @display_cache = nil - @wiki_includes_cache = nil + @wiki_words_cache = @published_cache = @display_cache = @wiki_includes_cache = + @wiki_references_cache = nil end def display_published diff --git a/app/models/web.rb b/app/models/web.rb index ad87f373..b510f298 100644 --- a/app/models/web.rb +++ b/app/models/web.rb @@ -1,8 +1,8 @@ -require "cgi" -require "page" -require "page_set" -require "wiki_words" -require "zip/zip" +require 'cgi' +require 'page' +require 'page_set' +require 'wiki_words' +require 'zip/zip' class Web attr_accessor :name, :password, :markup, :color, :safe_mode, :pages @@ -35,7 +35,7 @@ class Web def address=(the_address) if the_address != CGI.escape(the_address) - raise Instiki::ValidationError.new("Web name should contain only valid URI characters") + raise Instiki::ValidationError.new('Web name should contain only valid URI characters') end @address = the_address end @@ -162,6 +162,7 @@ class Web end private + # Returns an array of all the wiki words in any current revision def wiki_words pages.values.inject([]) { |wiki_words, page| wiki_words << page.wiki_words }.flatten.uniq diff --git a/test/unit/web_test.rb b/test/unit/web_test.rb index e550aee6..e9cdb52f 100755 --- a/test/unit/web_test.rb +++ b/test/unit/web_test.rb @@ -126,6 +126,19 @@ class WebTest < Test::Unit::TestCase } end + def test_new_page_linked_from_mother_page + # this was a bug in revision 204 + home = Page.new(@web, 'HomePage', 'This page refers to AnotherPage', + Time.local(2004, 4, 4, 16, 50), 'Alexey Verkhovsky') + another_page = Page.new(@web, 'AnotherPage', 'This is \AnotherPage', + Time.local(2004, 4, 4, 16, 51), 'Alexey Verkhovsky') + + @web.add_page(home) + @web.add_page(another_page) + + assert_equal [home], @web.select.pages_that_link_to('AnotherPage') + end + private def add_sample_pages