Feature #806 ยป 806.diff
| test/functional/wiki_controller_test.rb (working copy) | ||
|---|---|---|
|
assert_template 'special_page_index'
|
||
|
pages = assigns(:pages)
|
||
|
assert_not_nil pages
|
||
|
assert_equal 2, pages.size
|
||
|
assert_equal 3, pages.size
|
||
|
assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' },
|
||
|
:content => /CookBook documentation/
|
||
|
end
|
||
| ... | ... | |
|
get :index, :id => 999
|
||
|
assert_response 404
|
||
|
end
|
||
|
|
||
|
def test_wikilinks_use_headings_as_title
|
||
|
get :index, :id => 1, :page => 'Another_page'
|
||
|
assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' },
|
||
|
:content => /CookBook documentation/
|
||
|
assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/A_third_page' },
|
||
|
:content => /Yet another page/
|
||
|
end
|
||
|
|
||
|
def test_wikilink_with_explicit_titles
|
||
|
get :index, :id => 1, :page => 'A_third_page'
|
||
|
assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' },
|
||
|
:content => /Home page/
|
||
|
end
|
||
|
|
||
|
end
|
||
| test/fixtures/wiki_contents.yml (working copy) | ||
|---|---|---|
|
---
|
||
|
wiki_contents_001:
|
||
|
text: |-
|
||
|
h1. CookBook documentation
+ h1. CookBook documentation
|
||
|
|
||
|
+
|
||
|
|
||
|
Some updated [[documentation]] here with gzipped history
|
||
|
updated_on: 2007-03-07 00:10:51 +01:00
|
||
| ... | ... | |
|
h1. Another page
|
||
|
|
||
|
This is a link to a ticket: #2
|
||
|
|
||
|
This is a link back to the [[CookBook_documentation]]
|
||
|
|
||
|
This is a link to [[A_third_page]]
|
||
|
updated_on: 2007-03-08 00:18:07 +01:00
|
||
|
page_id: 2
|
||
|
id: 2
|
||
| ... | ... | |
|
version: 1
|
||
|
author_id: 1
|
||
|
comments:
|
||
|
wiki_contents_004:
|
||
|
text: |-
|
||
|
h1. Yet another page
|
||
|
|
||
|
Back to the [[CookBook_documentation|Home page]]
|
||
|
updated_on: 2007-03-08 00:18:07 +01:00
|
||
|
page_id: 4
|
||
|
id: 4
|
||
|
version: 1
|
||
|
author_id: 1
|
||
|
comments:
|
||
| test/fixtures/wiki_pages.yml (working copy) | ||
|---|---|---|
|
title: Start_page
|
||
|
id: 3
|
||
|
wiki_id: 2
|
||
|
wiki_pages_004:
|
||
|
created_on: 2007-03-08 00:18:07 +01:00
|
||
|
title: A_third_page
|
||
|
id: 4
|
||
|
wiki_id: 1
|
||
|
|
||
| test/fixtures/wiki_content_versions.yml (working copy) | ||
|---|---|---|
|
wiki_content_id: 1
|
||
|
compression: ""
|
||
|
data: |-
|
||
|
h1. CookBook documentation
+ h1. CookBook documentation
|
||
|
|
||
|
+
|
||
|
|
||
|
Some [[documentation]] here...
|
||
|
wiki_content_versions_002:
|
||
| ... | ... | |
|
wiki_content_id: 1
|
||
|
compression: ""
|
||
|
data: |-
|
||
|
h1. CookBook documentation
+ h1. CookBook documentation
|
||
|
|
||
|
+
|
||
|
|
||
|
Some updated [[documentation]] here...
|
||
|
wiki_content_versions_003:
|
||
| ... | ... | |
|
h1. Another page
|
||
|
|
||
|
This is a link to a ticket: #2
|
||
|
|
||
|
This is a link back to the [[CookBook_documentation]]
|
||
|
|
||
|
This is a link to [[A_third_page]]
|
||
|
updated_on: 2007-03-08 00:18:07 +01:00
|
||
|
page_id: 2
|
||
|
wiki_content_id: 2
|
||
| ... | ... | |
|
version: 1
|
||
|
author_id: 1
|
||
|
comments:
|
||
|
|
||
|
wiki_content_versions_005:
|
||
|
data: |-
|
||
|
h1. Another page
|
||
|
|
||
|
This is a link to a ticket: #2
|
||
|
|
||
|
This is a link back to the [[CookBook_documentation]]
|
||
|
|
||
|
This is a link to [[A_third_page]]
|
||
|
updated_on: 2007-03-08 00:18:07 +01:00
|
||
|
page_id: 4
|
||
|
wiki_content_id: 4
|
||
|
id: 5
|
||
|
version: 1
|
||
|
author_id: 1
|
||
|
comments:
|
||
| app/helpers/application_helper.rb (working copy) | ||
|---|---|---|
|
if link_project && link_project.wiki
|
||
|
# check if page exists
|
||
|
wiki_page = link_project.wiki.find_page(page)
|
||
|
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
|
||
|
link_to((title || (wiki_page ? wiki_page.content.first_heading : nil) || page),
|
||
|
format_wiki_link.call(link_project, Wiki.titleize(page)),
|
||
|
:class => ('wiki-page' + (wiki_page ? '' : ' new')))
|
||
|
else
|
||
|
# project or wiki doesn't exist
|
||
| app/models/wiki_content.rb (working copy) | ||
|---|---|---|
|
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||
|
validates_presence_of :text
|
||
|
|
||
|
def first_heading
|
||
|
matches = text.match(/^h1.\s(.*)/)
|
||
|
matches ? matches[1] : nil
|
||
|
end
|
||
|
|
||
|
acts_as_versioned
|
||
|
class Version
|
||
|
belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id'
|
||