##// END OF EJS Templates
Fixed: Wiki#find_page should not be case sensitive because page title uniqueness is not (#6987)....
Jean-Philippe Lang -
r4316:97140f6a7828
parent child
Show More
@@ -45,11 +45,11 class Wiki < ActiveRecord::Base
45 # find the page with the given title
45 # find the page with the given title
46 def find_page(title, options = {})
46 def find_page(title, options = {})
47 title = start_page if title.blank?
47 title = start_page if title.blank?
48 title = Wiki.titleize(title)
48 title = Wiki.titleize(title).downcase
49 page = pages.find_by_title(title)
49 page = pages.first(:conditions => ["LOWER(title) LIKE ?", title])
50 if !page && !(options[:with_redirect] == false)
50 if !page && !(options[:with_redirect] == false)
51 # search for a redirect
51 # search for a redirect
52 redirect = redirects.find_by_title(title)
52 redirect = redirects.first(:conditions => ["LOWER(title) LIKE ?", title])
53 page = find_page(redirect.redirects_to, :with_redirect => false) if redirect
53 page = find_page(redirect.redirects_to, :with_redirect => false) if redirect
54 end
54 end
55 page
55 page
@@ -18,7 +18,7
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19
19
20 class WikiRedirectTest < ActiveSupport::TestCase
20 class WikiRedirectTest < ActiveSupport::TestCase
21 fixtures :projects, :wikis
21 fixtures :projects, :wikis, :wiki_pages
22
22
23 def setup
23 def setup
24 @wiki = Wiki.find(1)
24 @wiki = Wiki.find(1)
@@ -33,6 +33,7 class WikiRedirectTest < ActiveSupport::TestCase
33 assert_equal 'New_title', @original.title
33 assert_equal 'New_title', @original.title
34 assert @wiki.redirects.find_by_title('Original_title')
34 assert @wiki.redirects.find_by_title('Original_title')
35 assert @wiki.find_page('Original title')
35 assert @wiki.find_page('Original title')
36 assert @wiki.find_page('ORIGINAL title')
36 end
37 end
37
38
38 def test_update_redirect
39 def test_update_redirect
@@ -39,6 +39,15 class WikiTest < ActiveSupport::TestCase
39 assert_equal "Another start page", @wiki.start_page
39 assert_equal "Another start page", @wiki.start_page
40 end
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 def test_titleize
51 def test_titleize
43 assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
52 assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
44 assert_equal 'テスト', Wiki.titleize('テスト')
53 assert_equal 'テスト', Wiki.titleize('テスト')
General Comments 0
You need to be logged in to leave comments. Login now