To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / test / functional / .svn / text-base / wiki_controller_test.rb.svn-base @ 442:753f1380d6bc
History | View | Annotate | Download (19.1 KB)
| 1 | 441:cbce1fd3b1b7 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
||
| 3 | 0:513646585e45 | Chris | # |
| 4 | # This program is free software; you can redistribute it and/or |
||
| 5 | # modify it under the terms of the GNU General Public License |
||
| 6 | # as published by the Free Software Foundation; either version 2 |
||
| 7 | # of the License, or (at your option) any later version. |
||
| 8 | 441:cbce1fd3b1b7 | Chris | # |
| 9 | 0:513646585e45 | Chris | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 12 | # GNU General Public License for more details. |
||
| 13 | 441:cbce1fd3b1b7 | Chris | # |
| 14 | 0:513646585e45 | Chris | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program; if not, write to the Free Software |
||
| 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||
| 17 | |||
| 18 | 119:8661b858af72 | Chris | require File.expand_path('../../test_helper', __FILE__)
|
| 19 | 0:513646585e45 | Chris | require 'wiki_controller' |
| 20 | |||
| 21 | # Re-raise errors caught by the controller. |
||
| 22 | class WikiController; def rescue_action(e) raise e end; end |
||
| 23 | |||
| 24 | class WikiControllerTest < ActionController::TestCase |
||
| 25 | fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments |
||
| 26 | 441:cbce1fd3b1b7 | Chris | |
| 27 | 0:513646585e45 | Chris | def setup |
| 28 | @controller = WikiController.new |
||
| 29 | @request = ActionController::TestRequest.new |
||
| 30 | @response = ActionController::TestResponse.new |
||
| 31 | User.current = nil |
||
| 32 | end |
||
| 33 | 441:cbce1fd3b1b7 | Chris | |
| 34 | 0:513646585e45 | Chris | def test_show_start_page |
| 35 | 37:94944d00e43c | chris | get :show, :project_id => 'ecookbook' |
| 36 | 0:513646585e45 | Chris | assert_response :success |
| 37 | assert_template 'show' |
||
| 38 | assert_tag :tag => 'h1', :content => /CookBook documentation/ |
||
| 39 | |||
| 40 | # child_pages macro |
||
| 41 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
|
||
| 42 | :child => { :tag => 'li',
|
||
| 43 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
|
||
| 44 | :content => 'Page with an inline image' } } |
||
| 45 | end |
||
| 46 | 441:cbce1fd3b1b7 | Chris | |
| 47 | 0:513646585e45 | Chris | def test_show_page_with_name |
| 48 | 37:94944d00e43c | chris | get :show, :project_id => 1, :id => 'Another_page' |
| 49 | 0:513646585e45 | Chris | assert_response :success |
| 50 | assert_template 'show' |
||
| 51 | assert_tag :tag => 'h1', :content => /Another page/ |
||
| 52 | # Included page with an inline image |
||
| 53 | assert_tag :tag => 'p', :content => /This is an inline image/ |
||
| 54 | assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
|
||
| 55 | :alt => 'This is a logo' } |
||
| 56 | end |
||
| 57 | 441:cbce1fd3b1b7 | Chris | |
| 58 | def test_show_redirected_page |
||
| 59 | WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page') |
||
| 60 | |||
| 61 | get :show, :project_id => 'ecookbook', :id => 'Old_title' |
||
| 62 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
||
| 63 | end |
||
| 64 | |||
| 65 | 0:513646585e45 | Chris | def test_show_with_sidebar |
| 66 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') |
||
| 67 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') |
||
| 68 | page.save! |
||
| 69 | 441:cbce1fd3b1b7 | Chris | |
| 70 | 37:94944d00e43c | chris | get :show, :project_id => 1, :id => 'Another_page' |
| 71 | 0:513646585e45 | Chris | assert_response :success |
| 72 | assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
|
||
| 73 | :content => /Side bar content for test_show_with_sidebar/ |
||
| 74 | end |
||
| 75 | 441:cbce1fd3b1b7 | Chris | |
| 76 | 0:513646585e45 | Chris | def test_show_unexistent_page_without_edit_right |
| 77 | 37:94944d00e43c | chris | get :show, :project_id => 1, :id => 'Unexistent page' |
| 78 | 0:513646585e45 | Chris | assert_response 404 |
| 79 | end |
||
| 80 | 441:cbce1fd3b1b7 | Chris | |
| 81 | 0:513646585e45 | Chris | def test_show_unexistent_page_with_edit_right |
| 82 | @request.session[:user_id] = 2 |
||
| 83 | 37:94944d00e43c | chris | get :show, :project_id => 1, :id => 'Unexistent page' |
| 84 | 0:513646585e45 | Chris | assert_response :success |
| 85 | assert_template 'edit' |
||
| 86 | end |
||
| 87 | 441:cbce1fd3b1b7 | Chris | |
| 88 | 0:513646585e45 | Chris | def test_create_page |
| 89 | @request.session[:user_id] = 2 |
||
| 90 | 37:94944d00e43c | chris | put :update, :project_id => 1, |
| 91 | :id => 'New page', |
||
| 92 | 0:513646585e45 | Chris | :content => {:comments => 'Created the page',
|
| 93 | :text => "h1. New page\n\nThis is a new page", |
||
| 94 | :version => 0} |
||
| 95 | 37:94944d00e43c | chris | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' |
| 96 | 0:513646585e45 | Chris | page = Project.find(1).wiki.find_page('New page')
|
| 97 | assert !page.new_record? |
||
| 98 | assert_not_nil page.content |
||
| 99 | assert_equal 'Created the page', page.content.comments |
||
| 100 | end |
||
| 101 | 441:cbce1fd3b1b7 | Chris | |
| 102 | 0:513646585e45 | Chris | def test_create_page_with_attachments |
| 103 | @request.session[:user_id] = 2 |
||
| 104 | assert_difference 'WikiPage.count' do |
||
| 105 | assert_difference 'Attachment.count' do |
||
| 106 | 37:94944d00e43c | chris | put :update, :project_id => 1, |
| 107 | :id => 'New page', |
||
| 108 | 0:513646585e45 | Chris | :content => {:comments => 'Created the page',
|
| 109 | :text => "h1. New page\n\nThis is a new page", |
||
| 110 | :version => 0}, |
||
| 111 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
|
||
| 112 | end |
||
| 113 | end |
||
| 114 | page = Project.find(1).wiki.find_page('New page')
|
||
| 115 | assert_equal 1, page.attachments.count |
||
| 116 | assert_equal 'testfile.txt', page.attachments.first.filename |
||
| 117 | end |
||
| 118 | 119:8661b858af72 | Chris | |
| 119 | def test_update_page |
||
| 120 | @request.session[:user_id] = 2 |
||
| 121 | assert_no_difference 'WikiPage.count' do |
||
| 122 | assert_no_difference 'WikiContent.count' do |
||
| 123 | assert_difference 'WikiContent::Version.count' do |
||
| 124 | put :update, :project_id => 1, |
||
| 125 | :id => 'Another_page', |
||
| 126 | :content => {
|
||
| 127 | :comments => "my comments", |
||
| 128 | :text => "edited", |
||
| 129 | :version => 1 |
||
| 130 | } |
||
| 131 | end |
||
| 132 | end |
||
| 133 | end |
||
| 134 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
||
| 135 | 441:cbce1fd3b1b7 | Chris | |
| 136 | 119:8661b858af72 | Chris | page = Wiki.find(1).pages.find_by_title('Another_page')
|
| 137 | assert_equal "edited", page.content.text |
||
| 138 | assert_equal 2, page.content.version |
||
| 139 | assert_equal "my comments", page.content.comments |
||
| 140 | end |
||
| 141 | |||
| 142 | def test_update_page_with_failure |
||
| 143 | @request.session[:user_id] = 2 |
||
| 144 | assert_no_difference 'WikiPage.count' do |
||
| 145 | assert_no_difference 'WikiContent.count' do |
||
| 146 | assert_no_difference 'WikiContent::Version.count' do |
||
| 147 | put :update, :project_id => 1, |
||
| 148 | :id => 'Another_page', |
||
| 149 | :content => {
|
||
| 150 | :comments => 'a' * 300, # failure here, comment is too long |
||
| 151 | :text => 'edited', |
||
| 152 | :version => 1 |
||
| 153 | } |
||
| 154 | end |
||
| 155 | end |
||
| 156 | end |
||
| 157 | assert_response :success |
||
| 158 | assert_template 'edit' |
||
| 159 | 441:cbce1fd3b1b7 | Chris | |
| 160 | 119:8661b858af72 | Chris | assert_error_tag :descendant => {:content => /Comment is too long/}
|
| 161 | assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited'
|
||
| 162 | assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
|
||
| 163 | end |
||
| 164 | 441:cbce1fd3b1b7 | Chris | |
| 165 | def test_update_stale_page_should_not_raise_an_error |
||
| 166 | @request.session[:user_id] = 2 |
||
| 167 | c = Wiki.find(1).find_page('Another_page').content
|
||
| 168 | c.text = 'Previous text' |
||
| 169 | c.save! |
||
| 170 | assert_equal 2, c.version |
||
| 171 | |||
| 172 | assert_no_difference 'WikiPage.count' do |
||
| 173 | assert_no_difference 'WikiContent.count' do |
||
| 174 | assert_no_difference 'WikiContent::Version.count' do |
||
| 175 | put :update, :project_id => 1, |
||
| 176 | :id => 'Another_page', |
||
| 177 | :content => {
|
||
| 178 | :comments => 'My comments', |
||
| 179 | :text => 'Text should not be lost', |
||
| 180 | :version => 1 |
||
| 181 | } |
||
| 182 | end |
||
| 183 | end |
||
| 184 | end |
||
| 185 | assert_response :success |
||
| 186 | assert_template 'edit' |
||
| 187 | assert_tag :div, |
||
| 188 | :attributes => { :class => /error/ },
|
||
| 189 | :content => /Data has been updated by another user/ |
||
| 190 | assert_tag 'textarea', |
||
| 191 | :attributes => { :name => 'content[text]' },
|
||
| 192 | :content => /Text should not be lost/ |
||
| 193 | assert_tag 'input', |
||
| 194 | :attributes => { :name => 'content[comments]', :value => 'My comments' }
|
||
| 195 | |||
| 196 | c.reload |
||
| 197 | assert_equal 'Previous text', c.text |
||
| 198 | assert_equal 2, c.version |
||
| 199 | end |
||
| 200 | |||
| 201 | 0:513646585e45 | Chris | def test_preview |
| 202 | @request.session[:user_id] = 2 |
||
| 203 | 37:94944d00e43c | chris | xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', |
| 204 | 0:513646585e45 | Chris | :content => { :comments => '',
|
| 205 | :text => 'this is a *previewed text*', |
||
| 206 | :version => 3 } |
||
| 207 | assert_response :success |
||
| 208 | assert_template 'common/_preview' |
||
| 209 | assert_tag :tag => 'strong', :content => /previewed text/ |
||
| 210 | end |
||
| 211 | 441:cbce1fd3b1b7 | Chris | |
| 212 | 0:513646585e45 | Chris | def test_preview_new_page |
| 213 | @request.session[:user_id] = 2 |
||
| 214 | 37:94944d00e43c | chris | xhr :post, :preview, :project_id => 1, :id => 'New page', |
| 215 | 0:513646585e45 | Chris | :content => { :text => 'h1. New page',
|
| 216 | :comments => '', |
||
| 217 | :version => 0 } |
||
| 218 | assert_response :success |
||
| 219 | assert_template 'common/_preview' |
||
| 220 | assert_tag :tag => 'h1', :content => /New page/ |
||
| 221 | end |
||
| 222 | 441:cbce1fd3b1b7 | Chris | |
| 223 | 0:513646585e45 | Chris | def test_history |
| 224 | 37:94944d00e43c | chris | get :history, :project_id => 1, :id => 'CookBook_documentation' |
| 225 | 0:513646585e45 | Chris | assert_response :success |
| 226 | assert_template 'history' |
||
| 227 | assert_not_nil assigns(:versions) |
||
| 228 | assert_equal 3, assigns(:versions).size |
||
| 229 | assert_select "input[type=submit][name=commit]" |
||
| 230 | end |
||
| 231 | |||
| 232 | def test_history_with_one_version |
||
| 233 | 37:94944d00e43c | chris | get :history, :project_id => 1, :id => 'Another_page' |
| 234 | 0:513646585e45 | Chris | assert_response :success |
| 235 | assert_template 'history' |
||
| 236 | assert_not_nil assigns(:versions) |
||
| 237 | assert_equal 1, assigns(:versions).size |
||
| 238 | assert_select "input[type=submit][name=commit]", false |
||
| 239 | end |
||
| 240 | 441:cbce1fd3b1b7 | Chris | |
| 241 | 0:513646585e45 | Chris | def test_diff |
| 242 | 37:94944d00e43c | chris | get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1 |
| 243 | 0:513646585e45 | Chris | assert_response :success |
| 244 | assert_template 'diff' |
||
| 245 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
|
||
| 246 | :content => /updated/ |
||
| 247 | end |
||
| 248 | 441:cbce1fd3b1b7 | Chris | |
| 249 | 0:513646585e45 | Chris | def test_annotate |
| 250 | 37:94944d00e43c | chris | get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 |
| 251 | 0:513646585e45 | Chris | assert_response :success |
| 252 | assert_template 'annotate' |
||
| 253 | # Line 1 |
||
| 254 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
|
||
| 255 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
|
||
| 256 | :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
|
||
| 257 | # Line 2 |
||
| 258 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
|
||
| 259 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
|
||
| 260 | :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
|
||
| 261 | end |
||
| 262 | 37:94944d00e43c | chris | |
| 263 | def test_get_rename |
||
| 264 | @request.session[:user_id] = 2 |
||
| 265 | get :rename, :project_id => 1, :id => 'Another_page' |
||
| 266 | assert_response :success |
||
| 267 | assert_template 'rename' |
||
| 268 | assert_tag 'option', |
||
| 269 | :attributes => {:value => ''},
|
||
| 270 | :content => '', |
||
| 271 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
|
||
| 272 | assert_no_tag 'option', |
||
| 273 | :attributes => {:selected => 'selected'},
|
||
| 274 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
|
||
| 275 | end |
||
| 276 | 441:cbce1fd3b1b7 | Chris | |
| 277 | 37:94944d00e43c | chris | def test_get_rename_child_page |
| 278 | @request.session[:user_id] = 2 |
||
| 279 | get :rename, :project_id => 1, :id => 'Child_1' |
||
| 280 | assert_response :success |
||
| 281 | assert_template 'rename' |
||
| 282 | assert_tag 'option', |
||
| 283 | :attributes => {:value => ''},
|
||
| 284 | :content => '', |
||
| 285 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
|
||
| 286 | assert_tag 'option', |
||
| 287 | :attributes => {:value => '2', :selected => 'selected'},
|
||
| 288 | :content => /Another page/, |
||
| 289 | :parent => {
|
||
| 290 | :tag => 'select', |
||
| 291 | :attributes => {:name => 'wiki_page[parent_id]'}
|
||
| 292 | } |
||
| 293 | end |
||
| 294 | 441:cbce1fd3b1b7 | Chris | |
| 295 | 0:513646585e45 | Chris | def test_rename_with_redirect |
| 296 | @request.session[:user_id] = 2 |
||
| 297 | 37:94944d00e43c | chris | post :rename, :project_id => 1, :id => 'Another_page', |
| 298 | 0:513646585e45 | Chris | :wiki_page => { :title => 'Another renamed page',
|
| 299 | :redirect_existing_links => 1 } |
||
| 300 | 37:94944d00e43c | chris | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
| 301 | 0:513646585e45 | Chris | wiki = Project.find(1).wiki |
| 302 | # Check redirects |
||
| 303 | assert_not_nil wiki.find_page('Another page')
|
||
| 304 | assert_nil wiki.find_page('Another page', :with_redirect => false)
|
||
| 305 | end |
||
| 306 | |||
| 307 | def test_rename_without_redirect |
||
| 308 | @request.session[:user_id] = 2 |
||
| 309 | 37:94944d00e43c | chris | post :rename, :project_id => 1, :id => 'Another_page', |
| 310 | 0:513646585e45 | Chris | :wiki_page => { :title => 'Another renamed page',
|
| 311 | :redirect_existing_links => "0" } |
||
| 312 | 37:94944d00e43c | chris | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
| 313 | 0:513646585e45 | Chris | wiki = Project.find(1).wiki |
| 314 | # Check that there's no redirects |
||
| 315 | assert_nil wiki.find_page('Another page')
|
||
| 316 | end |
||
| 317 | 441:cbce1fd3b1b7 | Chris | |
| 318 | 37:94944d00e43c | chris | def test_rename_with_parent_assignment |
| 319 | @request.session[:user_id] = 2 |
||
| 320 | post :rename, :project_id => 1, :id => 'Another_page', |
||
| 321 | :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
|
||
| 322 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
||
| 323 | assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
|
||
| 324 | end |
||
| 325 | |||
| 326 | def test_rename_with_parent_unassignment |
||
| 327 | @request.session[:user_id] = 2 |
||
| 328 | post :rename, :project_id => 1, :id => 'Child_1', |
||
| 329 | :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
|
||
| 330 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' |
||
| 331 | assert_nil WikiPage.find_by_title('Child_1').parent
|
||
| 332 | end |
||
| 333 | 441:cbce1fd3b1b7 | Chris | |
| 334 | 0:513646585e45 | Chris | def test_destroy_child |
| 335 | @request.session[:user_id] = 2 |
||
| 336 | 37:94944d00e43c | chris | delete :destroy, :project_id => 1, :id => 'Child_1' |
| 337 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
||
| 338 | 0:513646585e45 | Chris | end |
| 339 | 441:cbce1fd3b1b7 | Chris | |
| 340 | 0:513646585e45 | Chris | def test_destroy_parent |
| 341 | @request.session[:user_id] = 2 |
||
| 342 | assert_no_difference('WikiPage.count') do
|
||
| 343 | 37:94944d00e43c | chris | delete :destroy, :project_id => 1, :id => 'Another_page' |
| 344 | 0:513646585e45 | Chris | end |
| 345 | assert_response :success |
||
| 346 | assert_template 'destroy' |
||
| 347 | end |
||
| 348 | 441:cbce1fd3b1b7 | Chris | |
| 349 | 0:513646585e45 | Chris | def test_destroy_parent_with_nullify |
| 350 | @request.session[:user_id] = 2 |
||
| 351 | assert_difference('WikiPage.count', -1) do
|
||
| 352 | 37:94944d00e43c | chris | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify' |
| 353 | 0:513646585e45 | Chris | end |
| 354 | 37:94944d00e43c | chris | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
| 355 | 0:513646585e45 | Chris | assert_nil WikiPage.find_by_id(2) |
| 356 | end |
||
| 357 | 441:cbce1fd3b1b7 | Chris | |
| 358 | 0:513646585e45 | Chris | def test_destroy_parent_with_cascade |
| 359 | @request.session[:user_id] = 2 |
||
| 360 | assert_difference('WikiPage.count', -3) do
|
||
| 361 | 37:94944d00e43c | chris | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy' |
| 362 | 0:513646585e45 | Chris | end |
| 363 | 37:94944d00e43c | chris | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
| 364 | 0:513646585e45 | Chris | assert_nil WikiPage.find_by_id(2) |
| 365 | assert_nil WikiPage.find_by_id(5) |
||
| 366 | end |
||
| 367 | 441:cbce1fd3b1b7 | Chris | |
| 368 | 0:513646585e45 | Chris | def test_destroy_parent_with_reassign |
| 369 | @request.session[:user_id] = 2 |
||
| 370 | assert_difference('WikiPage.count', -1) do
|
||
| 371 | 37:94944d00e43c | chris | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 |
| 372 | 0:513646585e45 | Chris | end |
| 373 | 37:94944d00e43c | chris | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
| 374 | 0:513646585e45 | Chris | assert_nil WikiPage.find_by_id(2) |
| 375 | assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent |
||
| 376 | end |
||
| 377 | 441:cbce1fd3b1b7 | Chris | |
| 378 | 37:94944d00e43c | chris | def test_index |
| 379 | get :index, :project_id => 'ecookbook' |
||
| 380 | 0:513646585e45 | Chris | assert_response :success |
| 381 | 37:94944d00e43c | chris | assert_template 'index' |
| 382 | 0:513646585e45 | Chris | pages = assigns(:pages) |
| 383 | assert_not_nil pages |
||
| 384 | assert_equal Project.find(1).wiki.pages.size, pages.size |
||
| 385 | 441:cbce1fd3b1b7 | Chris | assert_equal pages.first.content.updated_on, pages.first.updated_on |
| 386 | |||
| 387 | 0:513646585e45 | Chris | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
|
| 388 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
|
||
| 389 | :content => 'CookBook documentation' }, |
||
| 390 | :child => { :tag => 'ul',
|
||
| 391 | :child => { :tag => 'li',
|
||
| 392 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
|
||
| 393 | :content => 'Page with an inline image' } } } }, |
||
| 394 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
|
||
| 395 | :content => 'Another page' } } |
||
| 396 | end |
||
| 397 | 37:94944d00e43c | chris | |
| 398 | 441:cbce1fd3b1b7 | Chris | def test_index_should_include_atom_link |
| 399 | get :index, :project_id => 'ecookbook' |
||
| 400 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
|
||
| 401 | end |
||
| 402 | |||
| 403 | 37:94944d00e43c | chris | context "GET :export" do |
| 404 | context "with an authorized user to export the wiki" do |
||
| 405 | setup do |
||
| 406 | @request.session[:user_id] = 2 |
||
| 407 | get :export, :project_id => 'ecookbook' |
||
| 408 | end |
||
| 409 | 441:cbce1fd3b1b7 | Chris | |
| 410 | 37:94944d00e43c | chris | should_respond_with :success |
| 411 | should_assign_to :pages |
||
| 412 | should_respond_with_content_type "text/html" |
||
| 413 | should "export all of the wiki pages to a single html file" do |
||
| 414 | assert_select "a[name=?]", "CookBook_documentation" |
||
| 415 | assert_select "a[name=?]", "Another_page" |
||
| 416 | assert_select "a[name=?]", "Page_with_an_inline_image" |
||
| 417 | end |
||
| 418 | 441:cbce1fd3b1b7 | Chris | |
| 419 | 37:94944d00e43c | chris | end |
| 420 | |||
| 421 | context "with an unauthorized user" do |
||
| 422 | setup do |
||
| 423 | get :export, :project_id => 'ecookbook' |
||
| 424 | |||
| 425 | should_respond_with :redirect |
||
| 426 | should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
|
||
| 427 | end |
||
| 428 | end |
||
| 429 | end |
||
| 430 | |||
| 431 | context "GET :date_index" do |
||
| 432 | setup do |
||
| 433 | get :date_index, :project_id => 'ecookbook' |
||
| 434 | end |
||
| 435 | |||
| 436 | should_respond_with :success |
||
| 437 | should_assign_to :pages |
||
| 438 | should_assign_to :pages_by_date |
||
| 439 | should_render_template 'wiki/date_index' |
||
| 440 | 441:cbce1fd3b1b7 | Chris | |
| 441 | should "include atom link" do |
||
| 442 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
|
||
| 443 | end |
||
| 444 | 37:94944d00e43c | chris | end |
| 445 | 441:cbce1fd3b1b7 | Chris | |
| 446 | 0:513646585e45 | Chris | def test_not_found |
| 447 | 37:94944d00e43c | chris | get :show, :project_id => 999 |
| 448 | 0:513646585e45 | Chris | assert_response 404 |
| 449 | end |
||
| 450 | 441:cbce1fd3b1b7 | Chris | |
| 451 | 0:513646585e45 | Chris | def test_protect_page |
| 452 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') |
||
| 453 | assert !page.protected? |
||
| 454 | @request.session[:user_id] = 2 |
||
| 455 | 37:94944d00e43c | chris | post :protect, :project_id => 1, :id => page.title, :protected => '1' |
| 456 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
||
| 457 | 0:513646585e45 | Chris | assert page.reload.protected? |
| 458 | end |
||
| 459 | 441:cbce1fd3b1b7 | Chris | |
| 460 | 0:513646585e45 | Chris | def test_unprotect_page |
| 461 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') |
||
| 462 | assert page.protected? |
||
| 463 | @request.session[:user_id] = 2 |
||
| 464 | 37:94944d00e43c | chris | post :protect, :project_id => 1, :id => page.title, :protected => '0' |
| 465 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' |
||
| 466 | 0:513646585e45 | Chris | assert !page.reload.protected? |
| 467 | end |
||
| 468 | 441:cbce1fd3b1b7 | Chris | |
| 469 | 0:513646585e45 | Chris | def test_show_page_with_edit_link |
| 470 | @request.session[:user_id] = 2 |
||
| 471 | 37:94944d00e43c | chris | get :show, :project_id => 1 |
| 472 | 0:513646585e45 | Chris | assert_response :success |
| 473 | assert_template 'show' |
||
| 474 | assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
|
||
| 475 | end |
||
| 476 | 441:cbce1fd3b1b7 | Chris | |
| 477 | 0:513646585e45 | Chris | def test_show_page_without_edit_link |
| 478 | @request.session[:user_id] = 4 |
||
| 479 | 37:94944d00e43c | chris | get :show, :project_id => 1 |
| 480 | 0:513646585e45 | Chris | assert_response :success |
| 481 | assert_template 'show' |
||
| 482 | assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
|
||
| 483 | 441:cbce1fd3b1b7 | Chris | end |
| 484 | |||
| 485 | 0:513646585e45 | Chris | def test_edit_unprotected_page |
| 486 | # Non members can edit unprotected wiki pages |
||
| 487 | @request.session[:user_id] = 4 |
||
| 488 | 37:94944d00e43c | chris | get :edit, :project_id => 1, :id => 'Another_page' |
| 489 | 0:513646585e45 | Chris | assert_response :success |
| 490 | assert_template 'edit' |
||
| 491 | end |
||
| 492 | 441:cbce1fd3b1b7 | Chris | |
| 493 | 0:513646585e45 | Chris | def test_edit_protected_page_by_nonmember |
| 494 | # Non members can't edit protected wiki pages |
||
| 495 | @request.session[:user_id] = 4 |
||
| 496 | 37:94944d00e43c | chris | get :edit, :project_id => 1, :id => 'CookBook_documentation' |
| 497 | 0:513646585e45 | Chris | assert_response 403 |
| 498 | end |
||
| 499 | 441:cbce1fd3b1b7 | Chris | |
| 500 | 0:513646585e45 | Chris | def test_edit_protected_page_by_member |
| 501 | @request.session[:user_id] = 2 |
||
| 502 | 37:94944d00e43c | chris | get :edit, :project_id => 1, :id => 'CookBook_documentation' |
| 503 | 0:513646585e45 | Chris | assert_response :success |
| 504 | 441:cbce1fd3b1b7 | Chris | assert_template 'edit' |
| 505 | 0:513646585e45 | Chris | end |
| 506 | 441:cbce1fd3b1b7 | Chris | |
| 507 | 0:513646585e45 | Chris | def test_history_of_non_existing_page_should_return_404 |
| 508 | 37:94944d00e43c | chris | get :history, :project_id => 1, :id => 'Unknown_page' |
| 509 | 0:513646585e45 | Chris | assert_response 404 |
| 510 | end |
||
| 511 | end |