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