# find the page with the given title
def find_page(title, options = {})
title = start_page if title.blank?
- title = Wiki.titleize(title)
- page = pages.find_by_title(title)
+ title = Wiki.titleize(title).downcase
+ page = pages.first(:conditions => ["LOWER(title) LIKE ?", title])
if !page && !(options[:with_redirect] == false)
# search for a redirect
- redirect = redirects.find_by_title(title)
+ redirect = redirects.first(:conditions => ["LOWER(title) LIKE ?", title])
page = find_page(redirect.redirects_to, :with_redirect => false) if redirect
end
page
require File.dirname(__FILE__) + '/../test_helper'
class WikiRedirectTest < ActiveSupport::TestCase
- fixtures :projects, :wikis
+ fixtures :projects, :wikis, :wiki_pages
def setup
@wiki = Wiki.find(1)
assert_equal 'New_title', @original.title
assert @wiki.redirects.find_by_title('Original_title')
assert @wiki.find_page('Original title')
+ assert @wiki.find_page('ORIGINAL title')
end
def test_update_redirect
assert_equal "Another start page", @wiki.start_page
end
+ def test_find_page
+ wiki = Wiki.find(1)
+ page = WikiPage.find(2)
+
+ assert_equal page, wiki.find_page('Another_page')
+ assert_equal page, wiki.find_page('Another page')
+ assert_equal page, wiki.find_page('ANOTHER page')
+ end
+
def test_titleize
assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
assert_equal 'テスト', Wiki.titleize('テスト')