@@ -45,11 +45,11 class Wiki < ActiveRecord::Base | |||
|
45 | 45 | # find the page with the given title |
|
46 | 46 | def find_page(title, options = {}) |
|
47 | 47 | title = start_page if title.blank? |
|
48 | title = Wiki.titleize(title) | |
|
49 | page = pages.find_by_title(title) | |
|
48 | title = Wiki.titleize(title).downcase | |
|
49 | page = pages.first(:conditions => ["LOWER(title) LIKE ?", title]) | |
|
50 | 50 | if !page && !(options[:with_redirect] == false) |
|
51 | 51 | # search for a redirect |
|
52 |
redirect = redirects.fi |
|
|
52 | redirect = redirects.first(:conditions => ["LOWER(title) LIKE ?", title]) | |
|
53 | 53 | page = find_page(redirect.redirects_to, :with_redirect => false) if redirect |
|
54 | 54 | end |
|
55 | 55 | page |
@@ -18,7 +18,7 | |||
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | |
|
20 | 20 | class WikiRedirectTest < ActiveSupport::TestCase |
|
21 | fixtures :projects, :wikis | |
|
21 | fixtures :projects, :wikis, :wiki_pages | |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | @wiki = Wiki.find(1) |
@@ -33,6 +33,7 class WikiRedirectTest < ActiveSupport::TestCase | |||
|
33 | 33 | assert_equal 'New_title', @original.title |
|
34 | 34 | assert @wiki.redirects.find_by_title('Original_title') |
|
35 | 35 | assert @wiki.find_page('Original title') |
|
36 | assert @wiki.find_page('ORIGINAL title') | |
|
36 | 37 | end |
|
37 | 38 | |
|
38 | 39 | def test_update_redirect |
@@ -39,6 +39,15 class WikiTest < ActiveSupport::TestCase | |||
|
39 | 39 | assert_equal "Another start page", @wiki.start_page |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | def test_find_page | |
|
43 | wiki = Wiki.find(1) | |
|
44 | page = WikiPage.find(2) | |
|
45 | ||
|
46 | assert_equal page, wiki.find_page('Another_page') | |
|
47 | assert_equal page, wiki.find_page('Another page') | |
|
48 | assert_equal page, wiki.find_page('ANOTHER page') | |
|
49 | end | |
|
50 | ||
|
42 | 51 | def test_titleize |
|
43 | 52 | assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES') |
|
44 | 53 | assert_equal 'テスト', Wiki.titleize('テスト') |
General Comments 0
You need to be logged in to leave comments.
Login now