Feature #806 ยป 806.diff
| test/functional/wiki_controller_test.rb (working copy) | ||
|---|---|---|
| 147 | 147 | assert_template 'special_page_index' | 
| 148 | 148 | pages = assigns(:pages) | 
| 149 | 149 | assert_not_nil pages | 
| 150 |     assert_equal 2, pages.size | |
| 150 |     assert_equal 3, pages.size | |
| 151 | 151 |     assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' }, | 
| 152 | 152 | :content => /CookBook documentation/ | 
| 153 | 153 | end | 
| ... | ... | |
| 156 | 156 | get :index, :id => 999 | 
| 157 | 157 | assert_response 404 | 
| 158 | 158 | end | 
| 159 |  | |
| 160 | def test_wikilinks_use_headings_as_title | |
| 161 | get :index, :id => 1, :page => 'Another_page' | |
| 162 |     assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' }, | |
| 163 | :content => /CookBook documentation/ | |
| 164 |     assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/A_third_page' }, | |
| 165 | :content => /Yet another page/ | |
| 166 | end | |
| 167 |  | |
| 168 | def test_wikilink_with_explicit_titles | |
| 169 | get :index, :id => 1, :page => 'A_third_page' | |
| 170 |     assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' }, | |
| 171 | :content => /Home page/ | |
| 172 | ||
| 173 | end | |
| 174 |  | |
| 159 | 175 | end | 
| test/fixtures/wiki_contents.yml (working copy) | ||
|---|---|---|
| 1 | 1 | --- | 
| 2 | 2 | wiki_contents_001: | 
| 3 | 3 | text: |- | 
| 4 | h1. CookBook documentation + h1. CookBook documentation | |
| 5 | 4 |  | 
| 6 | + | |
| 7 | 5 |  | 
| 8 | 6 | Some updated [[documentation]] here with gzipped history | 
| 9 | 7 | updated_on: 2007-03-07 00:10:51 +01:00 | 
| ... | ... | |
| 17 | 17 | h1. Another page | 
| 18 | 18 |  | 
| 19 | 19 | This is a link to a ticket: #2 | 
| 20 |  | |
| 21 | This is a link back to the [[CookBook_documentation]] | |
| 22 |  | |
| 23 | This is a link to [[A_third_page]] | |
| 20 | 24 | updated_on: 2007-03-08 00:18:07 +01:00 | 
| 21 | 25 | page_id: 2 | 
| 22 | 26 | id: 2 | 
| ... | ... | |
| 34 | 38 | version: 1 | 
| 35 | 39 | author_id: 1 | 
| 36 | 40 | comments: | 
| 41 | wiki_contents_004: | |
| 42 | text: |- | |
| 43 | h1. Yet another page | |
| 44 |  | |
| 45 | Back to the [[CookBook_documentation|Home page]] | |
| 46 | updated_on: 2007-03-08 00:18:07 +01:00 | |
| 47 | page_id: 4 | |
| 48 | id: 4 | |
| 49 | version: 1 | |
| 50 | author_id: 1 | |
| 51 | comments: | |
| test/fixtures/wiki_pages.yml (working copy) | ||
|---|---|---|
| 14 | 14 | title: Start_page | 
| 15 | 15 | id: 3 | 
| 16 | 16 | wiki_id: 2 | 
| 17 | wiki_pages_004: | |
| 18 | created_on: 2007-03-08 00:18:07 +01:00 | |
| 19 | title: A_third_page | |
| 20 | id: 4 | |
| 21 | wiki_id: 1 | |
| 17 | 22 |  | 
| test/fixtures/wiki_content_versions.yml (working copy) | ||
|---|---|---|
| 9 | 9 | wiki_content_id: 1 | 
| 10 | 10 | compression: "" | 
| 11 | 11 | data: |- | 
| 12 | h1. CookBook documentation + h1. CookBook documentation | |
| 13 | 12 |  | 
| 14 | + | |
| 15 | 13 |  | 
| 16 | 14 | Some [[documentation]] here... | 
| 17 | 15 | wiki_content_versions_002: | 
| ... | ... | |
| 24 | 24 | wiki_content_id: 1 | 
| 25 | 25 | compression: "" | 
| 26 | 26 | data: |- | 
| 27 | h1. CookBook documentation + h1. CookBook documentation | |
| 28 | 27 |  | 
| 29 | + | |
| 30 | 28 |  | 
| 31 | 29 | Some updated [[documentation]] here... | 
| 32 | 30 | wiki_content_versions_003: | 
| ... | ... | |
| 46 | 46 | h1. Another page | 
| 47 | 47 |  | 
| 48 | 48 | This is a link to a ticket: #2 | 
| 49 |  | |
| 50 | This is a link back to the [[CookBook_documentation]] | |
| 51 |  | |
| 52 | This is a link to [[A_third_page]] | |
| 49 | 53 | updated_on: 2007-03-08 00:18:07 +01:00 | 
| 50 | 54 | page_id: 2 | 
| 51 | 55 | wiki_content_id: 2 | 
| ... | ... | |
| 53 | 57 | version: 1 | 
| 54 | 58 | author_id: 1 | 
| 55 | 59 | comments: | 
| 56 |  | |
| 60 | wiki_content_versions_005: | |
| 61 | data: |- | |
| 62 | h1. Another page | |
| 63 |  | |
| 64 | This is a link to a ticket: #2 | |
| 65 |  | |
| 66 | This is a link back to the [[CookBook_documentation]] | |
| 67 |  | |
| 68 | This is a link to [[A_third_page]] | |
| 69 | updated_on: 2007-03-08 00:18:07 +01:00 | |
| 70 | page_id: 4 | |
| 71 | wiki_content_id: 4 | |
| 72 | id: 5 | |
| 73 | version: 1 | |
| 74 | author_id: 1 | |
| 75 | comments: | |
| app/helpers/application_helper.rb (working copy) | ||
|---|---|---|
| 252 | 252 | if link_project && link_project.wiki | 
| 253 | 253 | # check if page exists | 
| 254 | 254 | wiki_page = link_project.wiki.find_page(page) | 
| 255 | link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)), | |
| 255 | link_to((title || (wiki_page ? wiki_page.content.first_heading : nil) || page), | |
| 256 | format_wiki_link.call(link_project, Wiki.titleize(page)), | |
| 256 | 257 |                                    :class => ('wiki-page' + (wiki_page ? '' : ' new'))) | 
| 257 | 258 | else | 
| 258 | 259 | # project or wiki doesn't exist | 
| app/models/wiki_content.rb (working copy) | ||
|---|---|---|
| 23 | 23 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' | 
| 24 | 24 | validates_presence_of :text | 
| 25 | 25 |  | 
| 26 | def first_heading | |
| 27 | matches = text.match(/^h1.\s(.*)/) | |
| 28 | matches ? matches[1] : nil | |
| 29 | end | |
| 30 |  | |
| 26 | 31 | acts_as_versioned | 
| 27 | 32 | class Version | 
| 28 | 33 | belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id' |