From 541a5d39942cd74aced59ef7dde2a3c3fd61da67 Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Sun, 11 Sep 2005 08:05:19 +0000 Subject: [PATCH] Deleted all references to PageRenderer from PageSet selectors; using wiki_references instead --- app/controllers/application.rb | 2 ++ app/models/page.rb | 4 ---- app/models/page_set.rb | 11 +++++++---- test/functional/admin_controller_test.rb | 3 +-- test/functional/wiki_controller_test.rb | 2 +- test/test_helper.rb | 3 +++ test/unit/web_test.rb | 4 ++-- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 2208066a..05fb89ce 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base before_filter :set_utf8_http_header, :connect_to_model, :setup_url_generator after_filter :remember_location, :teardown_url_generator + observer :page_observer + # For injecting a different wiki model implementation. Intended for use in tests def self.wiki=(the_wiki) # a global variable is used here because Rails reloads controller and model classes in the diff --git a/app/models/page.rb b/app/models/page.rb index 44d76102..715ac6ce 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -4,10 +4,6 @@ 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/app/models/page_set.rb b/app/models/page_set.rb index 9fd43ca9..d806e5a8 100644 --- a/app/models/page_set.rb +++ b/app/models/page_set.rb @@ -31,15 +31,18 @@ class PageSet < Array end def pages_that_reference(page_name) - self.select { |page| PageRenderer.new(page.revisions.last).wiki_references.include?(page_name) } + all_referring_pages = WikiReference.pages_that_reference(page_name) + self.select { |page| all_referring_pages.include?(page.name) } end def pages_that_link_to(page_name) - self.select { |page| PageRenderer.new(page.revisions.last).wiki_words.include?(page_name) } + all_linking_pages = WikiReference.pages_that_link_to(page_name) + self.select { |page| all_linking_pages.include?(page.name) } end def pages_that_include(page_name) - self.select { |page| PageRenderer.new(page.revisions.last).wiki_includes.include?(page_name) } + all_including_pages = WikiReference.pages_that_include(page_name) + self.select { |page| all_including_pages.include?(page.name) } end def pages_authored_by(author) @@ -78,7 +81,7 @@ class PageSet < Array end def wiki_words - self.inject([]) { |wiki_words, page| wiki_words << PageRenderer.new(page.revisions.last).wiki_words }.flatten.uniq + self.inject([]) { |wiki_words, page| WikiReference.wiki_words(page) }.flatten.uniq end def authors diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb index 886041fd..6df919f3 100644 --- a/test/functional/admin_controller_test.rb +++ b/test/functional/admin_controller_test.rb @@ -7,7 +7,7 @@ require 'admin_controller' class AdminController; def rescue_action(e) logger.error(e); raise e end; end class AdminControllerTest < Test::Unit::TestCase - fixtures :webs, :pages, :revisions, :system + fixtures :webs, :pages, :revisions, :system, :wiki_references def setup @controller = AdminController.new @@ -204,7 +204,6 @@ class AdminControllerTest < Test::Unit::TestCase assert_equal page_order, @web.select.sort, "Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}" - # Oak is now orphan, second pass should remove it r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd') assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list' diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index ea33e717..54c541b3 100755 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -14,7 +14,7 @@ require 'zip/zipfilesystem' class WikiController; def rescue_action(e) logger.error(e); raise e end; end class WikiControllerTest < Test::Unit::TestCase - fixtures :webs, :pages, :revisions, :system + fixtures :webs, :pages, :revisions, :system, :wiki_references def setup @controller = WikiController.new diff --git a/test/test_helper.rb b/test/test_helper.rb index 928c2e49..adf78cf2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -20,6 +20,9 @@ require 'url_generator' Test::Unit::TestCase.use_instantiated_fixtures = false Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/" +# activate PageObserver +PageObserver.instance + class Test::Unit::TestCase def create_fixtures(*table_names) Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures", table_names) diff --git a/test/unit/web_test.rb b/test/unit/web_test.rb index ea08523a..875c0bb3 100644 --- a/test/unit/web_test.rb +++ b/test/unit/web_test.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper') class WebTest < Test::Unit::TestCase - fixtures :webs, :pages, :revisions, :system + fixtures :webs, :pages, :revisions, :system, :wiki_references def setup @web = webs(:instiki) @@ -78,7 +78,7 @@ class WebTest < Test::Unit::TestCase 'This is an author page, it should not be an orphan', Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', test_renderer) self_linked = @web.add_page('SelfLinked', - 'I am me SelfLinked and link to EverBeenInLove', + 'I am SelfLinked and link to EverBeenInLove', Time.local(2004, 4, 4, 16, 50), 'AnonymousCoward', test_renderer) # page that links to itself, and nobody else links to it must be an orphan