##// END OF EJS Templates
3.3-stable: fix test failure (#23700)...
Toshi MARUYAMA -
r15411:ceeca4a88d80
parent child
Show More
@@ -1,1031 +1,1031
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2016 Jean-Philippe Lang
2 # Copyright (C) 2006-2016 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.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class WikiControllerTest < ActionController::TestCase
20 class WikiControllerTest < ActionController::TestCase
21 fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
21 fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
22 :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
22 :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
23 :wiki_content_versions, :attachments,
23 :wiki_content_versions, :attachments,
24 :issues, :issue_statuses, :trackers
24 :issues, :issue_statuses, :trackers
25
25
26 def setup
26 def setup
27 User.current = nil
27 User.current = nil
28 end
28 end
29
29
30 def test_show_start_page
30 def test_show_start_page
31 get :show, :project_id => 'ecookbook'
31 get :show, :project_id => 'ecookbook'
32 assert_response :success
32 assert_response :success
33 assert_template 'show'
33 assert_template 'show'
34 assert_select 'h1', :text => /CookBook documentation/
34 assert_select 'h1', :text => /CookBook documentation/
35
35
36 # child_pages macro
36 # child_pages macro
37 assert_select 'ul.pages-hierarchy>li>a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image',
37 assert_select 'ul.pages-hierarchy>li>a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image',
38 :text => 'Page with an inline image'
38 :text => 'Page with an inline image'
39 end
39 end
40
40
41 def test_export_link
41 def test_export_link
42 Role.anonymous.add_permission! :export_wiki_pages
42 Role.anonymous.add_permission! :export_wiki_pages
43 get :show, :project_id => 'ecookbook'
43 get :show, :project_id => 'ecookbook'
44 assert_response :success
44 assert_response :success
45 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation.txt'
45 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation.txt'
46 end
46 end
47
47
48 def test_show_page_with_name
48 def test_show_page_with_name
49 get :show, :project_id => 1, :id => 'Another_page'
49 get :show, :project_id => 1, :id => 'Another_page'
50 assert_response :success
50 assert_response :success
51 assert_template 'show'
51 assert_template 'show'
52 assert_select 'h1', :text => /Another page/
52 assert_select 'h1', :text => /Another page/
53 # Included page with an inline image
53 # Included page with an inline image
54 assert_select 'p', :text => /This is an inline image/
54 assert_select 'p', :text => /This is an inline image/
55 assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo'
55 assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo'
56 end
56 end
57
57
58 def test_show_old_version
58 def test_show_old_version
59 with_settings :default_language => 'en' do
59 with_settings :default_language => 'en' do
60 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'
60 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'
61 end
61 end
62 assert_response :success
62 assert_response :success
63 assert_template 'show'
63 assert_template 'show'
64
64
65 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/1', :text => /Previous/
65 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/1', :text => /Previous/
66 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/diff', :text => /diff/
66 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/diff', :text => /diff/
67 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/3', :text => /Next/
67 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/3', :text => /Next/
68 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/
68 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/
69 end
69 end
70
70
71 def test_show_old_version_with_attachments
71 def test_show_old_version_with_attachments
72 page = WikiPage.find(4)
72 page = WikiPage.find(4)
73 assert page.attachments.any?
73 assert page.attachments.any?
74 content = page.content
74 content = page.content
75 content.text = "update"
75 content.text = "update"
76 content.save!
76 content.save!
77
77
78 get :show, :project_id => 'ecookbook', :id => page.title, :version => '1'
78 get :show, :project_id => 'ecookbook', :id => page.title, :version => '1'
79 assert_kind_of WikiContent::Version, assigns(:content)
79 assert_kind_of WikiContent::Version, assigns(:content)
80 assert_response :success
80 assert_response :success
81 assert_template 'show'
81 assert_template 'show'
82 end
82 end
83
83
84 def test_show_old_version_without_permission_should_be_denied
84 def test_show_old_version_without_permission_should_be_denied
85 Role.anonymous.remove_permission! :view_wiki_edits
85 Role.anonymous.remove_permission! :view_wiki_edits
86
86
87 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'
87 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'
88 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fprojects%2Fecookbook%2Fwiki%2FCookBook_documentation%2F2'
88 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fprojects%2Fecookbook%2Fwiki%2FCookBook_documentation%2F2'
89 end
89 end
90
90
91 def test_show_first_version
91 def test_show_first_version
92 with_settings :default_language => 'en' do
92 with_settings :default_language => 'en' do
93 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '1'
93 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '1'
94 end
94 end
95 assert_response :success
95 assert_response :success
96 assert_template 'show'
96 assert_template 'show'
97
97
98 assert_select 'a', :text => /Previous/, :count => 0
98 assert_select 'a', :text => /Previous/, :count => 0
99 assert_select 'a', :text => /diff/, :count => 0
99 assert_select 'a', :text => /diff/, :count => 0
100 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => /Next/
100 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => /Next/
101 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/
101 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/
102 end
102 end
103
103
104 def test_show_redirected_page
104 def test_show_redirected_page
105 WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
105 WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
106
106
107 get :show, :project_id => 'ecookbook', :id => 'Old_title'
107 get :show, :project_id => 'ecookbook', :id => 'Old_title'
108 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
108 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
109 end
109 end
110
110
111 def test_show_with_sidebar
111 def test_show_with_sidebar
112 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
112 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
113 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
113 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
114 page.save!
114 page.save!
115
115
116 get :show, :project_id => 1, :id => 'Another_page'
116 get :show, :project_id => 1, :id => 'Another_page'
117 assert_response :success
117 assert_response :success
118 assert_select 'div#sidebar', :text => /Side bar content for test_show_with_sidebar/
118 assert_select 'div#sidebar', :text => /Side bar content for test_show_with_sidebar/
119 end
119 end
120
120
121 def test_show_should_display_section_edit_links
121 def test_show_should_display_section_edit_links
122 @request.session[:user_id] = 2
122 @request.session[:user_id] = 2
123 get :show, :project_id => 1, :id => 'Page with sections'
123 get :show, :project_id => 1, :id => 'Page with sections'
124
124
125 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0
125 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0
126 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
126 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
127 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3'
127 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3'
128 end
128 end
129
129
130 def test_show_current_version_should_display_section_edit_links
130 def test_show_current_version_should_display_section_edit_links
131 @request.session[:user_id] = 2
131 @request.session[:user_id] = 2
132 get :show, :project_id => 1, :id => 'Page with sections', :version => 3
132 get :show, :project_id => 1, :id => 'Page with sections', :version => 3
133
133
134 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
134 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
135 end
135 end
136
136
137 def test_show_old_version_should_not_display_section_edit_links
137 def test_show_old_version_should_not_display_section_edit_links
138 @request.session[:user_id] = 2
138 @request.session[:user_id] = 2
139 get :show, :project_id => 1, :id => 'Page with sections', :version => 2
139 get :show, :project_id => 1, :id => 'Page with sections', :version => 2
140
140
141 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2', 0
141 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2', 0
142 end
142 end
143
143
144 def test_show_unexistent_page_without_edit_right
144 def test_show_unexistent_page_without_edit_right
145 get :show, :project_id => 1, :id => 'Unexistent page'
145 get :show, :project_id => 1, :id => 'Unexistent page'
146 assert_response 404
146 assert_response 404
147 end
147 end
148
148
149 def test_show_unexistent_page_with_edit_right
149 def test_show_unexistent_page_with_edit_right
150 @request.session[:user_id] = 2
150 @request.session[:user_id] = 2
151 get :show, :project_id => 1, :id => 'Unexistent page'
151 get :show, :project_id => 1, :id => 'Unexistent page'
152 assert_response :success
152 assert_response :success
153 assert_template 'edit'
153 assert_template 'edit'
154 end
154 end
155
155
156 def test_show_specific_version_of_an_unexistent_page_without_edit_right
156 def test_show_specific_version_of_an_unexistent_page_without_edit_right
157 get :show, :project_id => 1, :id => 'Unexistent page', :version => 1
157 get :show, :project_id => 1, :id => 'Unexistent page', :version => 1
158 assert_response 404
158 assert_response 404
159 end
159 end
160
160
161 def test_show_unexistent_page_with_parent_should_preselect_parent
161 def test_show_unexistent_page_with_parent_should_preselect_parent
162 @request.session[:user_id] = 2
162 @request.session[:user_id] = 2
163 get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page'
163 get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page'
164 assert_response :success
164 assert_response :success
165 assert_template 'edit'
165 assert_template 'edit'
166 assert_select 'select[name=?] option[value="2"][selected=selected]', 'wiki_page[parent_id]'
166 assert_select 'select[name=?] option[value="2"][selected=selected]', 'wiki_page[parent_id]'
167 end
167 end
168
168
169 def test_show_should_not_show_history_without_permission
169 def test_show_should_not_show_history_without_permission
170 Role.anonymous.remove_permission! :view_wiki_edits
170 Role.anonymous.remove_permission! :view_wiki_edits
171 get :show, :project_id => 1, :id => 'Page with sections', :version => 2
171 get :show, :project_id => 1, :id => 'Page with sections', :version => 2
172
172
173 assert_response 302
173 assert_response 302
174 end
174 end
175
175
176 def test_show_page_without_content_should_display_the_edit_form
176 def test_show_page_without_content_should_display_the_edit_form
177 @request.session[:user_id] = 2
177 @request.session[:user_id] = 2
178 WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki)
178 WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki)
179
179
180 get :show, :project_id => 1, :id => 'NoContent'
180 get :show, :project_id => 1, :id => 'NoContent'
181 assert_response :success
181 assert_response :success
182 assert_template 'edit'
182 assert_template 'edit'
183 assert_select 'textarea[name=?]', 'content[text]'
183 assert_select 'textarea[name=?]', 'content[text]'
184 end
184 end
185
185
186 def test_get_new
186 def test_get_new
187 @request.session[:user_id] = 2
187 @request.session[:user_id] = 2
188
188
189 get :new, :project_id => 'ecookbook'
189 get :new, :project_id => 'ecookbook'
190 assert_response :success
190 assert_response :success
191 assert_template 'new'
191 assert_template 'new'
192 end
192 end
193
193
194 def test_get_new_xhr
194 def test_get_new_xhr
195 @request.session[:user_id] = 2
195 @request.session[:user_id] = 2
196
196
197 xhr :get, :new, :project_id => 'ecookbook'
197 xhr :get, :new, :project_id => 'ecookbook'
198 assert_response :success
198 assert_response :success
199 assert_template 'new'
199 assert_template 'new'
200 end
200 end
201
201
202 def test_post_new_with_valid_title_should_redirect_to_edit
202 def test_post_new_with_valid_title_should_redirect_to_edit
203 @request.session[:user_id] = 2
203 @request.session[:user_id] = 2
204
204
205 post :new, :project_id => 'ecookbook', :title => 'New Page'
205 post :new, :project_id => 'ecookbook', :title => 'New Page'
206 assert_redirected_to '/projects/ecookbook/wiki/New_Page'
206 assert_redirected_to '/projects/ecookbook/wiki/New_Page'
207 end
207 end
208
208
209 def test_post_new_xhr_with_valid_title_should_redirect_to_edit
209 def test_post_new_xhr_with_valid_title_should_redirect_to_edit
210 @request.session[:user_id] = 2
210 @request.session[:user_id] = 2
211
211
212 xhr :post, :new, :project_id => 'ecookbook', :title => 'New Page'
212 xhr :post, :new, :project_id => 'ecookbook', :title => 'New Page'
213 assert_response :success
213 assert_response :success
214 assert_equal 'window.location = "/projects/ecookbook/wiki/New_Page"', response.body
214 assert_equal 'window.location = "/projects/ecookbook/wiki/New_Page"', response.body
215 end
215 end
216
216
217 def test_post_new_with_invalid_title_should_display_errors
217 def test_post_new_with_invalid_title_should_display_errors
218 @request.session[:user_id] = 2
218 @request.session[:user_id] = 2
219
219
220 post :new, :project_id => 'ecookbook', :title => 'Another page'
220 post :new, :project_id => 'ecookbook', :title => 'Another page'
221 assert_response :success
221 assert_response :success
222 assert_template 'new'
222 assert_template 'new'
223 assert_select_error 'Title has already been taken'
223 assert_select_error 'Title has already been taken'
224 end
224 end
225
225
226 def test_post_new_with_protected_title_should_display_errors
226 def test_post_new_with_protected_title_should_display_errors
227 Role.find(1).remove_permission!(:protect_wiki_pages)
227 Role.find(1).remove_permission!(:protect_wiki_pages)
228 @request.session[:user_id] = 2
228 @request.session[:user_id] = 2
229
229
230 post :new, :params => {:project_id => 'ecookbook', :title => 'Sidebar'}
230 post :new, :project_id => 'ecookbook', :title => 'Sidebar'
231 assert_response :success
231 assert_response :success
232 assert_select_error /Title/
232 assert_select_error /Title/
233 end
233 end
234
234
235 def test_post_new_xhr_with_invalid_title_should_display_errors
235 def test_post_new_xhr_with_invalid_title_should_display_errors
236 @request.session[:user_id] = 2
236 @request.session[:user_id] = 2
237
237
238 xhr :post, :new, :project_id => 'ecookbook', :title => 'Another page'
238 xhr :post, :new, :project_id => 'ecookbook', :title => 'Another page'
239 assert_response :success
239 assert_response :success
240 assert_template 'new'
240 assert_template 'new'
241 assert_include 'Title has already been taken', response.body
241 assert_include 'Title has already been taken', response.body
242 end
242 end
243
243
244 def test_create_page
244 def test_create_page
245 @request.session[:user_id] = 2
245 @request.session[:user_id] = 2
246 assert_difference 'WikiPage.count' do
246 assert_difference 'WikiPage.count' do
247 assert_difference 'WikiContent.count' do
247 assert_difference 'WikiContent.count' do
248 put :update, :project_id => 1,
248 put :update, :project_id => 1,
249 :id => 'New page',
249 :id => 'New page',
250 :content => {:comments => 'Created the page',
250 :content => {:comments => 'Created the page',
251 :text => "h1. New page\n\nThis is a new page",
251 :text => "h1. New page\n\nThis is a new page",
252 :version => 0}
252 :version => 0}
253 end
253 end
254 end
254 end
255 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
255 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
256 page = Project.find(1).wiki.find_page('New page')
256 page = Project.find(1).wiki.find_page('New page')
257 assert !page.new_record?
257 assert !page.new_record?
258 assert_not_nil page.content
258 assert_not_nil page.content
259 assert_nil page.parent
259 assert_nil page.parent
260 assert_equal 'Created the page', page.content.comments
260 assert_equal 'Created the page', page.content.comments
261 end
261 end
262
262
263 def test_create_page_with_attachments
263 def test_create_page_with_attachments
264 @request.session[:user_id] = 2
264 @request.session[:user_id] = 2
265 assert_difference 'WikiPage.count' do
265 assert_difference 'WikiPage.count' do
266 assert_difference 'Attachment.count' do
266 assert_difference 'Attachment.count' do
267 put :update, :project_id => 1,
267 put :update, :project_id => 1,
268 :id => 'New page',
268 :id => 'New page',
269 :content => {:comments => 'Created the page',
269 :content => {:comments => 'Created the page',
270 :text => "h1. New page\n\nThis is a new page",
270 :text => "h1. New page\n\nThis is a new page",
271 :version => 0},
271 :version => 0},
272 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
272 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
273 end
273 end
274 end
274 end
275 page = Project.find(1).wiki.find_page('New page')
275 page = Project.find(1).wiki.find_page('New page')
276 assert_equal 1, page.attachments.count
276 assert_equal 1, page.attachments.count
277 assert_equal 'testfile.txt', page.attachments.first.filename
277 assert_equal 'testfile.txt', page.attachments.first.filename
278 end
278 end
279
279
280 def test_create_page_with_parent
280 def test_create_page_with_parent
281 @request.session[:user_id] = 2
281 @request.session[:user_id] = 2
282 assert_difference 'WikiPage.count' do
282 assert_difference 'WikiPage.count' do
283 put :update, :project_id => 1, :id => 'New page',
283 put :update, :project_id => 1, :id => 'New page',
284 :content => {:text => "h1. New page\n\nThis is a new page", :version => 0},
284 :content => {:text => "h1. New page\n\nThis is a new page", :version => 0},
285 :wiki_page => {:parent_id => 2}
285 :wiki_page => {:parent_id => 2}
286 end
286 end
287 page = Project.find(1).wiki.find_page('New page')
287 page = Project.find(1).wiki.find_page('New page')
288 assert_equal WikiPage.find(2), page.parent
288 assert_equal WikiPage.find(2), page.parent
289 end
289 end
290
290
291 def test_edit_page
291 def test_edit_page
292 @request.session[:user_id] = 2
292 @request.session[:user_id] = 2
293 get :edit, :project_id => 'ecookbook', :id => 'Another_page'
293 get :edit, :project_id => 'ecookbook', :id => 'Another_page'
294
294
295 assert_response :success
295 assert_response :success
296 assert_template 'edit'
296 assert_template 'edit'
297
297
298 assert_select 'textarea[name=?]', 'content[text]',
298 assert_select 'textarea[name=?]', 'content[text]',
299 :text => WikiPage.find_by_title('Another_page').content.text
299 :text => WikiPage.find_by_title('Another_page').content.text
300 end
300 end
301
301
302 def test_edit_section
302 def test_edit_section
303 @request.session[:user_id] = 2
303 @request.session[:user_id] = 2
304 get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2
304 get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2
305
305
306 assert_response :success
306 assert_response :success
307 assert_template 'edit'
307 assert_template 'edit'
308
308
309 page = WikiPage.find_by_title('Page_with_sections')
309 page = WikiPage.find_by_title('Page_with_sections')
310 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
310 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
311
311
312 assert_select 'textarea[name=?]', 'content[text]', :text => section
312 assert_select 'textarea[name=?]', 'content[text]', :text => section
313 assert_select 'input[name=section][type=hidden][value="2"]'
313 assert_select 'input[name=section][type=hidden][value="2"]'
314 assert_select 'input[name=section_hash][type=hidden][value=?]', hash
314 assert_select 'input[name=section_hash][type=hidden][value=?]', hash
315 end
315 end
316
316
317 def test_edit_invalid_section_should_respond_with_404
317 def test_edit_invalid_section_should_respond_with_404
318 @request.session[:user_id] = 2
318 @request.session[:user_id] = 2
319 get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10
319 get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10
320
320
321 assert_response 404
321 assert_response 404
322 end
322 end
323
323
324 def test_update_page
324 def test_update_page
325 @request.session[:user_id] = 2
325 @request.session[:user_id] = 2
326 assert_no_difference 'WikiPage.count' do
326 assert_no_difference 'WikiPage.count' do
327 assert_no_difference 'WikiContent.count' do
327 assert_no_difference 'WikiContent.count' do
328 assert_difference 'WikiContent::Version.count' do
328 assert_difference 'WikiContent::Version.count' do
329 put :update, :project_id => 1,
329 put :update, :project_id => 1,
330 :id => 'Another_page',
330 :id => 'Another_page',
331 :content => {
331 :content => {
332 :comments => "my comments",
332 :comments => "my comments",
333 :text => "edited",
333 :text => "edited",
334 :version => 1
334 :version => 1
335 }
335 }
336 end
336 end
337 end
337 end
338 end
338 end
339 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
339 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
340
340
341 page = Wiki.find(1).pages.find_by_title('Another_page')
341 page = Wiki.find(1).pages.find_by_title('Another_page')
342 assert_equal "edited", page.content.text
342 assert_equal "edited", page.content.text
343 assert_equal 2, page.content.version
343 assert_equal 2, page.content.version
344 assert_equal "my comments", page.content.comments
344 assert_equal "my comments", page.content.comments
345 end
345 end
346
346
347 def test_update_page_with_parent
347 def test_update_page_with_parent
348 @request.session[:user_id] = 2
348 @request.session[:user_id] = 2
349 assert_no_difference 'WikiPage.count' do
349 assert_no_difference 'WikiPage.count' do
350 assert_no_difference 'WikiContent.count' do
350 assert_no_difference 'WikiContent.count' do
351 assert_difference 'WikiContent::Version.count' do
351 assert_difference 'WikiContent::Version.count' do
352 put :update, :project_id => 1,
352 put :update, :project_id => 1,
353 :id => 'Another_page',
353 :id => 'Another_page',
354 :content => {
354 :content => {
355 :comments => "my comments",
355 :comments => "my comments",
356 :text => "edited",
356 :text => "edited",
357 :version => 1
357 :version => 1
358 },
358 },
359 :wiki_page => {:parent_id => '1'}
359 :wiki_page => {:parent_id => '1'}
360 end
360 end
361 end
361 end
362 end
362 end
363 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
363 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
364
364
365 page = Wiki.find(1).pages.find_by_title('Another_page')
365 page = Wiki.find(1).pages.find_by_title('Another_page')
366 assert_equal "edited", page.content.text
366 assert_equal "edited", page.content.text
367 assert_equal 2, page.content.version
367 assert_equal 2, page.content.version
368 assert_equal "my comments", page.content.comments
368 assert_equal "my comments", page.content.comments
369 assert_equal WikiPage.find(1), page.parent
369 assert_equal WikiPage.find(1), page.parent
370 end
370 end
371
371
372 def test_update_page_with_failure
372 def test_update_page_with_failure
373 @request.session[:user_id] = 2
373 @request.session[:user_id] = 2
374 assert_no_difference 'WikiPage.count' do
374 assert_no_difference 'WikiPage.count' do
375 assert_no_difference 'WikiContent.count' do
375 assert_no_difference 'WikiContent.count' do
376 assert_no_difference 'WikiContent::Version.count' do
376 assert_no_difference 'WikiContent::Version.count' do
377 put :update, :project_id => 1,
377 put :update, :project_id => 1,
378 :id => 'Another_page',
378 :id => 'Another_page',
379 :content => {
379 :content => {
380 :comments => 'a' * 1300, # failure here, comment is too long
380 :comments => 'a' * 1300, # failure here, comment is too long
381 :text => 'edited'
381 :text => 'edited'
382 },
382 },
383 :wiki_page => {
383 :wiki_page => {
384 :parent_id => ""
384 :parent_id => ""
385 }
385 }
386 end
386 end
387 end
387 end
388 end
388 end
389 assert_response :success
389 assert_response :success
390 assert_template 'edit'
390 assert_template 'edit'
391
391
392 assert_select_error /Comment is too long/
392 assert_select_error /Comment is too long/
393 assert_select 'textarea#content_text', :text => "edited"
393 assert_select 'textarea#content_text', :text => "edited"
394 assert_select 'input#content_version[value="1"]'
394 assert_select 'input#content_version[value="1"]'
395 end
395 end
396
396
397 def test_update_page_with_parent_change_only_should_not_create_content_version
397 def test_update_page_with_parent_change_only_should_not_create_content_version
398 @request.session[:user_id] = 2
398 @request.session[:user_id] = 2
399 assert_no_difference 'WikiPage.count' do
399 assert_no_difference 'WikiPage.count' do
400 assert_no_difference 'WikiContent.count' do
400 assert_no_difference 'WikiContent.count' do
401 assert_no_difference 'WikiContent::Version.count' do
401 assert_no_difference 'WikiContent::Version.count' do
402 put :update, :project_id => 1,
402 put :update, :project_id => 1,
403 :id => 'Another_page',
403 :id => 'Another_page',
404 :content => {
404 :content => {
405 :comments => '',
405 :comments => '',
406 :text => Wiki.find(1).find_page('Another_page').content.text,
406 :text => Wiki.find(1).find_page('Another_page').content.text,
407 :version => 1
407 :version => 1
408 },
408 },
409 :wiki_page => {:parent_id => '1'}
409 :wiki_page => {:parent_id => '1'}
410 end
410 end
411 end
411 end
412 end
412 end
413 page = Wiki.find(1).pages.find_by_title('Another_page')
413 page = Wiki.find(1).pages.find_by_title('Another_page')
414 assert_equal 1, page.content.version
414 assert_equal 1, page.content.version
415 assert_equal WikiPage.find(1), page.parent
415 assert_equal WikiPage.find(1), page.parent
416 end
416 end
417
417
418 def test_update_page_with_attachments_only_should_not_create_content_version
418 def test_update_page_with_attachments_only_should_not_create_content_version
419 @request.session[:user_id] = 2
419 @request.session[:user_id] = 2
420 assert_no_difference 'WikiPage.count' do
420 assert_no_difference 'WikiPage.count' do
421 assert_no_difference 'WikiContent.count' do
421 assert_no_difference 'WikiContent.count' do
422 assert_no_difference 'WikiContent::Version.count' do
422 assert_no_difference 'WikiContent::Version.count' do
423 assert_difference 'Attachment.count' do
423 assert_difference 'Attachment.count' do
424 put :update, :project_id => 1,
424 put :update, :project_id => 1,
425 :id => 'Another_page',
425 :id => 'Another_page',
426 :content => {
426 :content => {
427 :comments => '',
427 :comments => '',
428 :text => Wiki.find(1).find_page('Another_page').content.text,
428 :text => Wiki.find(1).find_page('Another_page').content.text,
429 :version => 1
429 :version => 1
430 },
430 },
431 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
431 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
432 end
432 end
433 end
433 end
434 end
434 end
435 end
435 end
436 page = Wiki.find(1).pages.find_by_title('Another_page')
436 page = Wiki.find(1).pages.find_by_title('Another_page')
437 assert_equal 1, page.content.version
437 assert_equal 1, page.content.version
438 end
438 end
439
439
440 def test_update_stale_page_should_not_raise_an_error
440 def test_update_stale_page_should_not_raise_an_error
441 @request.session[:user_id] = 2
441 @request.session[:user_id] = 2
442 c = Wiki.find(1).find_page('Another_page').content
442 c = Wiki.find(1).find_page('Another_page').content
443 c.text = 'Previous text'
443 c.text = 'Previous text'
444 c.save!
444 c.save!
445 assert_equal 2, c.version
445 assert_equal 2, c.version
446
446
447 assert_no_difference 'WikiPage.count' do
447 assert_no_difference 'WikiPage.count' do
448 assert_no_difference 'WikiContent.count' do
448 assert_no_difference 'WikiContent.count' do
449 assert_no_difference 'WikiContent::Version.count' do
449 assert_no_difference 'WikiContent::Version.count' do
450 put :update, :project_id => 1,
450 put :update, :project_id => 1,
451 :id => 'Another_page',
451 :id => 'Another_page',
452 :content => {
452 :content => {
453 :comments => 'My comments',
453 :comments => 'My comments',
454 :text => 'Text should not be lost',
454 :text => 'Text should not be lost',
455 :version => 1
455 :version => 1
456 }
456 }
457 end
457 end
458 end
458 end
459 end
459 end
460 assert_response :success
460 assert_response :success
461 assert_template 'edit'
461 assert_template 'edit'
462 assert_select 'div.error', :text => /Data has been updated by another user/
462 assert_select 'div.error', :text => /Data has been updated by another user/
463 assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/
463 assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/
464 assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments'
464 assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments'
465
465
466 c.reload
466 c.reload
467 assert_equal 'Previous text', c.text
467 assert_equal 'Previous text', c.text
468 assert_equal 2, c.version
468 assert_equal 2, c.version
469 end
469 end
470
470
471 def test_update_page_without_content_should_create_content
471 def test_update_page_without_content_should_create_content
472 @request.session[:user_id] = 2
472 @request.session[:user_id] = 2
473 page = WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki)
473 page = WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki)
474
474
475 assert_no_difference 'WikiPage.count' do
475 assert_no_difference 'WikiPage.count' do
476 assert_difference 'WikiContent.count' do
476 assert_difference 'WikiContent.count' do
477 put :update, :project_id => 1, :id => 'NoContent', :content => {:text => 'Some content'}
477 put :update, :project_id => 1, :id => 'NoContent', :content => {:text => 'Some content'}
478 assert_response 302
478 assert_response 302
479 end
479 end
480 end
480 end
481 assert_equal 'Some content', page.reload.content.text
481 assert_equal 'Some content', page.reload.content.text
482 end
482 end
483
483
484 def test_update_section
484 def test_update_section
485 @request.session[:user_id] = 2
485 @request.session[:user_id] = 2
486 page = WikiPage.find_by_title('Page_with_sections')
486 page = WikiPage.find_by_title('Page_with_sections')
487 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
487 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
488 text = page.content.text
488 text = page.content.text
489
489
490 assert_no_difference 'WikiPage.count' do
490 assert_no_difference 'WikiPage.count' do
491 assert_no_difference 'WikiContent.count' do
491 assert_no_difference 'WikiContent.count' do
492 assert_difference 'WikiContent::Version.count' do
492 assert_difference 'WikiContent::Version.count' do
493 put :update, :project_id => 1, :id => 'Page_with_sections',
493 put :update, :project_id => 1, :id => 'Page_with_sections',
494 :content => {
494 :content => {
495 :text => "New section content",
495 :text => "New section content",
496 :version => 3
496 :version => 3
497 },
497 },
498 :section => 2,
498 :section => 2,
499 :section_hash => hash
499 :section_hash => hash
500 end
500 end
501 end
501 end
502 end
502 end
503 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
503 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
504 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text
504 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text
505 end
505 end
506
506
507 def test_update_section_should_allow_stale_page_update
507 def test_update_section_should_allow_stale_page_update
508 @request.session[:user_id] = 2
508 @request.session[:user_id] = 2
509 page = WikiPage.find_by_title('Page_with_sections')
509 page = WikiPage.find_by_title('Page_with_sections')
510 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
510 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
511 text = page.content.text
511 text = page.content.text
512
512
513 assert_no_difference 'WikiPage.count' do
513 assert_no_difference 'WikiPage.count' do
514 assert_no_difference 'WikiContent.count' do
514 assert_no_difference 'WikiContent.count' do
515 assert_difference 'WikiContent::Version.count' do
515 assert_difference 'WikiContent::Version.count' do
516 put :update, :project_id => 1, :id => 'Page_with_sections',
516 put :update, :project_id => 1, :id => 'Page_with_sections',
517 :content => {
517 :content => {
518 :text => "New section content",
518 :text => "New section content",
519 :version => 2 # Current version is 3
519 :version => 2 # Current version is 3
520 },
520 },
521 :section => 2,
521 :section => 2,
522 :section_hash => hash
522 :section_hash => hash
523 end
523 end
524 end
524 end
525 end
525 end
526 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
526 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
527 page.reload
527 page.reload
528 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text
528 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text
529 assert_equal 4, page.content.version
529 assert_equal 4, page.content.version
530 end
530 end
531
531
532 def test_update_section_should_not_allow_stale_section_update
532 def test_update_section_should_not_allow_stale_section_update
533 @request.session[:user_id] = 2
533 @request.session[:user_id] = 2
534
534
535 assert_no_difference 'WikiPage.count' do
535 assert_no_difference 'WikiPage.count' do
536 assert_no_difference 'WikiContent.count' do
536 assert_no_difference 'WikiContent.count' do
537 assert_no_difference 'WikiContent::Version.count' do
537 assert_no_difference 'WikiContent::Version.count' do
538 put :update, :project_id => 1, :id => 'Page_with_sections',
538 put :update, :project_id => 1, :id => 'Page_with_sections',
539 :content => {
539 :content => {
540 :comments => 'My comments',
540 :comments => 'My comments',
541 :text => "Text should not be lost",
541 :text => "Text should not be lost",
542 :version => 3
542 :version => 3
543 },
543 },
544 :section => 2,
544 :section => 2,
545 :section_hash => Digest::MD5.hexdigest("wrong hash")
545 :section_hash => Digest::MD5.hexdigest("wrong hash")
546 end
546 end
547 end
547 end
548 end
548 end
549 assert_response :success
549 assert_response :success
550 assert_template 'edit'
550 assert_template 'edit'
551 assert_select 'div.error', :text => /Data has been updated by another user/
551 assert_select 'div.error', :text => /Data has been updated by another user/
552 assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/
552 assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/
553 assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments'
553 assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments'
554 end
554 end
555
555
556 def test_preview
556 def test_preview
557 @request.session[:user_id] = 2
557 @request.session[:user_id] = 2
558 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
558 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
559 :content => { :comments => '',
559 :content => { :comments => '',
560 :text => 'this is a *previewed text*',
560 :text => 'this is a *previewed text*',
561 :version => 3 }
561 :version => 3 }
562 assert_response :success
562 assert_response :success
563 assert_template 'common/_preview'
563 assert_template 'common/_preview'
564 assert_select 'strong', :text => /previewed text/
564 assert_select 'strong', :text => /previewed text/
565 end
565 end
566
566
567 def test_preview_new_page
567 def test_preview_new_page
568 @request.session[:user_id] = 2
568 @request.session[:user_id] = 2
569 xhr :post, :preview, :project_id => 1, :id => 'New page',
569 xhr :post, :preview, :project_id => 1, :id => 'New page',
570 :content => { :text => 'h1. New page',
570 :content => { :text => 'h1. New page',
571 :comments => '',
571 :comments => '',
572 :version => 0 }
572 :version => 0 }
573 assert_response :success
573 assert_response :success
574 assert_template 'common/_preview'
574 assert_template 'common/_preview'
575 assert_select 'h1', :text => /New page/
575 assert_select 'h1', :text => /New page/
576 end
576 end
577
577
578 def test_history
578 def test_history
579 @request.session[:user_id] = 2
579 @request.session[:user_id] = 2
580 get :history, :project_id => 'ecookbook', :id => 'CookBook_documentation'
580 get :history, :project_id => 'ecookbook', :id => 'CookBook_documentation'
581 assert_response :success
581 assert_response :success
582 assert_template 'history'
582 assert_template 'history'
583 assert_not_nil assigns(:versions)
583 assert_not_nil assigns(:versions)
584 assert_equal 3, assigns(:versions).size
584 assert_equal 3, assigns(:versions).size
585
585
586 assert_select "input[type=submit][name=commit]"
586 assert_select "input[type=submit][name=commit]"
587 assert_select 'td' do
587 assert_select 'td' do
588 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => '2'
588 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => '2'
589 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/annotate', :text => 'Annotate'
589 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/annotate', :text => 'Annotate'
590 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => 'Delete'
590 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => 'Delete'
591 end
591 end
592 end
592 end
593
593
594 def test_history_with_one_version
594 def test_history_with_one_version
595 @request.session[:user_id] = 2
595 @request.session[:user_id] = 2
596 get :history, :project_id => 'ecookbook', :id => 'Another_page'
596 get :history, :project_id => 'ecookbook', :id => 'Another_page'
597 assert_response :success
597 assert_response :success
598 assert_template 'history'
598 assert_template 'history'
599 assert_not_nil assigns(:versions)
599 assert_not_nil assigns(:versions)
600 assert_equal 1, assigns(:versions).size
600 assert_equal 1, assigns(:versions).size
601 assert_select "input[type=submit][name=commit]", false
601 assert_select "input[type=submit][name=commit]", false
602 assert_select 'td' do
602 assert_select 'td' do
603 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => '1'
603 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => '1'
604 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1/annotate', :text => 'Annotate'
604 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1/annotate', :text => 'Annotate'
605 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => 'Delete', :count => 0
605 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => 'Delete', :count => 0
606 end
606 end
607 end
607 end
608
608
609 def test_diff
609 def test_diff
610 content = WikiPage.find(1).content
610 content = WikiPage.find(1).content
611 assert_difference 'WikiContent::Version.count', 2 do
611 assert_difference 'WikiContent::Version.count', 2 do
612 content.text = "Line removed\nThis is a sample text for testing diffs"
612 content.text = "Line removed\nThis is a sample text for testing diffs"
613 content.save!
613 content.save!
614 content.text = "This is a sample text for testing diffs\nLine added"
614 content.text = "This is a sample text for testing diffs\nLine added"
615 content.save!
615 content.save!
616 end
616 end
617
617
618 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => content.version, :version_from => (content.version - 1)
618 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => content.version, :version_from => (content.version - 1)
619 assert_response :success
619 assert_response :success
620 assert_template 'diff'
620 assert_template 'diff'
621 assert_select 'span.diff_out', :text => 'Line removed'
621 assert_select 'span.diff_out', :text => 'Line removed'
622 assert_select 'span.diff_in', :text => 'Line added'
622 assert_select 'span.diff_in', :text => 'Line added'
623 end
623 end
624
624
625 def test_diff_with_invalid_version_should_respond_with_404
625 def test_diff_with_invalid_version_should_respond_with_404
626 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99'
626 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99'
627 assert_response 404
627 assert_response 404
628 end
628 end
629
629
630 def test_diff_with_invalid_version_from_should_respond_with_404
630 def test_diff_with_invalid_version_from_should_respond_with_404
631 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99', :version_from => '98'
631 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99', :version_from => '98'
632 assert_response 404
632 assert_response 404
633 end
633 end
634
634
635 def test_annotate
635 def test_annotate
636 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
636 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
637 assert_response :success
637 assert_response :success
638 assert_template 'annotate'
638 assert_template 'annotate'
639
639
640 # Line 1
640 # Line 1
641 assert_select 'table.annotate tr:nth-child(1)' do
641 assert_select 'table.annotate tr:nth-child(1)' do
642 assert_select 'th.line-num', :text => '1'
642 assert_select 'th.line-num', :text => '1'
643 assert_select 'td.author', :text => /John Smith/
643 assert_select 'td.author', :text => /John Smith/
644 assert_select 'td', :text => /h1\. CookBook documentation/
644 assert_select 'td', :text => /h1\. CookBook documentation/
645 end
645 end
646
646
647 # Line 5
647 # Line 5
648 assert_select 'table.annotate tr:nth-child(5)' do
648 assert_select 'table.annotate tr:nth-child(5)' do
649 assert_select 'th.line-num', :text => '5'
649 assert_select 'th.line-num', :text => '5'
650 assert_select 'td.author', :text => /Redmine Admin/
650 assert_select 'td.author', :text => /Redmine Admin/
651 assert_select 'td', :text => /Some updated \[\[documentation\]\] here/
651 assert_select 'td', :text => /Some updated \[\[documentation\]\] here/
652 end
652 end
653 end
653 end
654
654
655 def test_annotate_with_invalid_version_should_respond_with_404
655 def test_annotate_with_invalid_version_should_respond_with_404
656 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => '99'
656 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => '99'
657 assert_response 404
657 assert_response 404
658 end
658 end
659
659
660 def test_get_rename
660 def test_get_rename
661 @request.session[:user_id] = 2
661 @request.session[:user_id] = 2
662 get :rename, :project_id => 1, :id => 'Another_page'
662 get :rename, :project_id => 1, :id => 'Another_page'
663 assert_response :success
663 assert_response :success
664 assert_template 'rename'
664 assert_template 'rename'
665
665
666 assert_select 'select[name=?]', 'wiki_page[parent_id]' do
666 assert_select 'select[name=?]', 'wiki_page[parent_id]' do
667 assert_select 'option[value=""]', :text => ''
667 assert_select 'option[value=""]', :text => ''
668 assert_select 'option[selected=selected]', 0
668 assert_select 'option[selected=selected]', 0
669 end
669 end
670 end
670 end
671
671
672 def test_get_rename_child_page
672 def test_get_rename_child_page
673 @request.session[:user_id] = 2
673 @request.session[:user_id] = 2
674 get :rename, :project_id => 1, :id => 'Child_1'
674 get :rename, :project_id => 1, :id => 'Child_1'
675 assert_response :success
675 assert_response :success
676 assert_template 'rename'
676 assert_template 'rename'
677
677
678 assert_select 'select[name=?]', 'wiki_page[parent_id]' do
678 assert_select 'select[name=?]', 'wiki_page[parent_id]' do
679 assert_select 'option[value=""]', :text => ''
679 assert_select 'option[value=""]', :text => ''
680 assert_select 'option[value="2"][selected=selected]', :text => /Another page/
680 assert_select 'option[value="2"][selected=selected]', :text => /Another page/
681 end
681 end
682 end
682 end
683
683
684 def test_rename_with_redirect
684 def test_rename_with_redirect
685 @request.session[:user_id] = 2
685 @request.session[:user_id] = 2
686 post :rename, :project_id => 1, :id => 'Another_page',
686 post :rename, :project_id => 1, :id => 'Another_page',
687 :wiki_page => { :title => 'Another renamed page',
687 :wiki_page => { :title => 'Another renamed page',
688 :redirect_existing_links => 1 }
688 :redirect_existing_links => 1 }
689 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
689 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
690 wiki = Project.find(1).wiki
690 wiki = Project.find(1).wiki
691 # Check redirects
691 # Check redirects
692 assert_not_nil wiki.find_page('Another page')
692 assert_not_nil wiki.find_page('Another page')
693 assert_nil wiki.find_page('Another page', :with_redirect => false)
693 assert_nil wiki.find_page('Another page', :with_redirect => false)
694 end
694 end
695
695
696 def test_rename_without_redirect
696 def test_rename_without_redirect
697 @request.session[:user_id] = 2
697 @request.session[:user_id] = 2
698 post :rename, :project_id => 1, :id => 'Another_page',
698 post :rename, :project_id => 1, :id => 'Another_page',
699 :wiki_page => { :title => 'Another renamed page',
699 :wiki_page => { :title => 'Another renamed page',
700 :redirect_existing_links => "0" }
700 :redirect_existing_links => "0" }
701 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
701 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
702 wiki = Project.find(1).wiki
702 wiki = Project.find(1).wiki
703 # Check that there's no redirects
703 # Check that there's no redirects
704 assert_nil wiki.find_page('Another page')
704 assert_nil wiki.find_page('Another page')
705 end
705 end
706
706
707 def test_rename_with_parent_assignment
707 def test_rename_with_parent_assignment
708 @request.session[:user_id] = 2
708 @request.session[:user_id] = 2
709 post :rename, :project_id => 1, :id => 'Another_page',
709 post :rename, :project_id => 1, :id => 'Another_page',
710 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
710 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
711 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
711 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
712 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
712 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
713 end
713 end
714
714
715 def test_rename_with_parent_unassignment
715 def test_rename_with_parent_unassignment
716 @request.session[:user_id] = 2
716 @request.session[:user_id] = 2
717 post :rename, :project_id => 1, :id => 'Child_1',
717 post :rename, :project_id => 1, :id => 'Child_1',
718 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
718 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
719 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
719 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
720 assert_nil WikiPage.find_by_title('Child_1').parent
720 assert_nil WikiPage.find_by_title('Child_1').parent
721 end
721 end
722
722
723 def test_get_rename_should_show_target_projects_list
723 def test_get_rename_should_show_target_projects_list
724 @request.session[:user_id] = 2
724 @request.session[:user_id] = 2
725 project = Project.find(5)
725 project = Project.find(5)
726 project.enable_module! :wiki
726 project.enable_module! :wiki
727
727
728 get :rename, :project_id => 1, :id => 'Another_page'
728 get :rename, :project_id => 1, :id => 'Another_page'
729 assert_response :success
729 assert_response :success
730 assert_template 'rename'
730 assert_template 'rename'
731
731
732 assert_select 'select[name=?]', 'wiki_page[wiki_id]' do
732 assert_select 'select[name=?]', 'wiki_page[wiki_id]' do
733 assert_select 'option', 2
733 assert_select 'option', 2
734 assert_select 'option[value=?][selected=selected]', '1', :text => /eCookbook/
734 assert_select 'option[value=?][selected=selected]', '1', :text => /eCookbook/
735 assert_select 'option[value=?]', project.wiki.id.to_s, :text => /#{project.name}/
735 assert_select 'option[value=?]', project.wiki.id.to_s, :text => /#{project.name}/
736 end
736 end
737 end
737 end
738
738
739 def test_rename_with_move
739 def test_rename_with_move
740 @request.session[:user_id] = 2
740 @request.session[:user_id] = 2
741 project = Project.find(5)
741 project = Project.find(5)
742 project.enable_module! :wiki
742 project.enable_module! :wiki
743
743
744 post :rename, :project_id => 1, :id => 'Another_page',
744 post :rename, :project_id => 1, :id => 'Another_page',
745 :wiki_page => {
745 :wiki_page => {
746 :wiki_id => project.wiki.id.to_s,
746 :wiki_id => project.wiki.id.to_s,
747 :title => 'Another renamed page',
747 :title => 'Another renamed page',
748 :redirect_existing_links => 1
748 :redirect_existing_links => 1
749 }
749 }
750 assert_redirected_to '/projects/private-child/wiki/Another_renamed_page'
750 assert_redirected_to '/projects/private-child/wiki/Another_renamed_page'
751
751
752 page = WikiPage.find(2)
752 page = WikiPage.find(2)
753 assert_equal project.wiki.id, page.wiki_id
753 assert_equal project.wiki.id, page.wiki_id
754 end
754 end
755
755
756 def test_destroy_a_page_without_children_should_not_ask_confirmation
756 def test_destroy_a_page_without_children_should_not_ask_confirmation
757 @request.session[:user_id] = 2
757 @request.session[:user_id] = 2
758 delete :destroy, :project_id => 1, :id => 'Child_2'
758 delete :destroy, :project_id => 1, :id => 'Child_2'
759 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
759 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
760 end
760 end
761
761
762 def test_destroy_parent_should_ask_confirmation
762 def test_destroy_parent_should_ask_confirmation
763 @request.session[:user_id] = 2
763 @request.session[:user_id] = 2
764 assert_no_difference('WikiPage.count') do
764 assert_no_difference('WikiPage.count') do
765 delete :destroy, :project_id => 1, :id => 'Another_page'
765 delete :destroy, :project_id => 1, :id => 'Another_page'
766 end
766 end
767 assert_response :success
767 assert_response :success
768 assert_template 'destroy'
768 assert_template 'destroy'
769 assert_select 'form' do
769 assert_select 'form' do
770 assert_select 'input[name=todo][value=nullify]'
770 assert_select 'input[name=todo][value=nullify]'
771 assert_select 'input[name=todo][value=destroy]'
771 assert_select 'input[name=todo][value=destroy]'
772 assert_select 'input[name=todo][value=reassign]'
772 assert_select 'input[name=todo][value=reassign]'
773 end
773 end
774 end
774 end
775
775
776 def test_destroy_parent_with_nullify_should_delete_parent_only
776 def test_destroy_parent_with_nullify_should_delete_parent_only
777 @request.session[:user_id] = 2
777 @request.session[:user_id] = 2
778 assert_difference('WikiPage.count', -1) do
778 assert_difference('WikiPage.count', -1) do
779 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
779 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
780 end
780 end
781 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
781 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
782 assert_nil WikiPage.find_by_id(2)
782 assert_nil WikiPage.find_by_id(2)
783 end
783 end
784
784
785 def test_destroy_parent_with_cascade_should_delete_descendants
785 def test_destroy_parent_with_cascade_should_delete_descendants
786 @request.session[:user_id] = 2
786 @request.session[:user_id] = 2
787 assert_difference('WikiPage.count', -4) do
787 assert_difference('WikiPage.count', -4) do
788 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
788 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
789 end
789 end
790 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
790 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
791 assert_nil WikiPage.find_by_id(2)
791 assert_nil WikiPage.find_by_id(2)
792 assert_nil WikiPage.find_by_id(5)
792 assert_nil WikiPage.find_by_id(5)
793 end
793 end
794
794
795 def test_destroy_parent_with_reassign
795 def test_destroy_parent_with_reassign
796 @request.session[:user_id] = 2
796 @request.session[:user_id] = 2
797 assert_difference('WikiPage.count', -1) do
797 assert_difference('WikiPage.count', -1) do
798 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
798 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
799 end
799 end
800 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
800 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
801 assert_nil WikiPage.find_by_id(2)
801 assert_nil WikiPage.find_by_id(2)
802 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
802 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
803 end
803 end
804
804
805 def test_destroy_version
805 def test_destroy_version
806 @request.session[:user_id] = 2
806 @request.session[:user_id] = 2
807 assert_difference 'WikiContent::Version.count', -1 do
807 assert_difference 'WikiContent::Version.count', -1 do
808 assert_no_difference 'WikiContent.count' do
808 assert_no_difference 'WikiContent.count' do
809 assert_no_difference 'WikiPage.count' do
809 assert_no_difference 'WikiPage.count' do
810 delete :destroy_version, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 2
810 delete :destroy_version, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 2
811 assert_redirected_to '/projects/ecookbook/wiki/CookBook_documentation/history'
811 assert_redirected_to '/projects/ecookbook/wiki/CookBook_documentation/history'
812 end
812 end
813 end
813 end
814 end
814 end
815 end
815 end
816
816
817 def test_destroy_invalid_version_should_respond_with_404
817 def test_destroy_invalid_version_should_respond_with_404
818 @request.session[:user_id] = 2
818 @request.session[:user_id] = 2
819 assert_no_difference 'WikiContent::Version.count' do
819 assert_no_difference 'WikiContent::Version.count' do
820 assert_no_difference 'WikiContent.count' do
820 assert_no_difference 'WikiContent.count' do
821 assert_no_difference 'WikiPage.count' do
821 assert_no_difference 'WikiPage.count' do
822 delete :destroy_version, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 99
822 delete :destroy_version, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 99
823 end
823 end
824 end
824 end
825 end
825 end
826 assert_response 404
826 assert_response 404
827 end
827 end
828
828
829 def test_index
829 def test_index
830 get :index, :project_id => 'ecookbook'
830 get :index, :project_id => 'ecookbook'
831 assert_response :success
831 assert_response :success
832 assert_template 'index'
832 assert_template 'index'
833 pages = assigns(:pages)
833 pages = assigns(:pages)
834 assert_not_nil pages
834 assert_not_nil pages
835 assert_equal Project.find(1).wiki.pages.size, pages.size
835 assert_equal Project.find(1).wiki.pages.size, pages.size
836 assert_equal pages.first.content.updated_on, pages.first.updated_on
836 assert_equal pages.first.content.updated_on, pages.first.updated_on
837
837
838 assert_select 'ul.pages-hierarchy' do
838 assert_select 'ul.pages-hierarchy' do
839 assert_select 'li' do
839 assert_select 'li' do
840 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => 'CookBook documentation'
840 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => 'CookBook documentation'
841 assert_select 'ul li a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', :text => 'Page with an inline image'
841 assert_select 'ul li a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', :text => 'Page with an inline image'
842 end
842 end
843 assert_select 'li a[href=?]', '/projects/ecookbook/wiki/Another_page', :text => 'Another page'
843 assert_select 'li a[href=?]', '/projects/ecookbook/wiki/Another_page', :text => 'Another page'
844 end
844 end
845 end
845 end
846
846
847 def test_index_should_include_atom_link
847 def test_index_should_include_atom_link
848 get :index, :project_id => 'ecookbook'
848 get :index, :project_id => 'ecookbook'
849 assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1'
849 assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1'
850 end
850 end
851
851
852 def test_export_to_html
852 def test_export_to_html
853 @request.session[:user_id] = 2
853 @request.session[:user_id] = 2
854 get :export, :project_id => 'ecookbook'
854 get :export, :project_id => 'ecookbook'
855
855
856 assert_response :success
856 assert_response :success
857 assert_not_nil assigns(:pages)
857 assert_not_nil assigns(:pages)
858 assert assigns(:pages).any?
858 assert assigns(:pages).any?
859 assert_equal "text/html", @response.content_type
859 assert_equal "text/html", @response.content_type
860
860
861 assert_select "a[name=?]", "CookBook_documentation"
861 assert_select "a[name=?]", "CookBook_documentation"
862 assert_select "a[name=?]", "Another_page"
862 assert_select "a[name=?]", "Another_page"
863 assert_select "a[name=?]", "Page_with_an_inline_image"
863 assert_select "a[name=?]", "Page_with_an_inline_image"
864 end
864 end
865
865
866 def test_export_to_pdf
866 def test_export_to_pdf
867 @request.session[:user_id] = 2
867 @request.session[:user_id] = 2
868 get :export, :project_id => 'ecookbook', :format => 'pdf'
868 get :export, :project_id => 'ecookbook', :format => 'pdf'
869
869
870 assert_response :success
870 assert_response :success
871 assert_not_nil assigns(:pages)
871 assert_not_nil assigns(:pages)
872 assert assigns(:pages).any?
872 assert assigns(:pages).any?
873 assert_equal 'application/pdf', @response.content_type
873 assert_equal 'application/pdf', @response.content_type
874 assert_equal 'attachment; filename="ecookbook.pdf"', @response.headers['Content-Disposition']
874 assert_equal 'attachment; filename="ecookbook.pdf"', @response.headers['Content-Disposition']
875 assert @response.body.starts_with?('%PDF')
875 assert @response.body.starts_with?('%PDF')
876 end
876 end
877
877
878 def test_export_without_permission_should_be_denied
878 def test_export_without_permission_should_be_denied
879 @request.session[:user_id] = 2
879 @request.session[:user_id] = 2
880 Role.find_by_name('Manager').remove_permission! :export_wiki_pages
880 Role.find_by_name('Manager').remove_permission! :export_wiki_pages
881 get :export, :project_id => 'ecookbook'
881 get :export, :project_id => 'ecookbook'
882
882
883 assert_response 403
883 assert_response 403
884 end
884 end
885
885
886 def test_date_index
886 def test_date_index
887 get :date_index, :project_id => 'ecookbook'
887 get :date_index, :project_id => 'ecookbook'
888
888
889 assert_response :success
889 assert_response :success
890 assert_template 'date_index'
890 assert_template 'date_index'
891 assert_not_nil assigns(:pages)
891 assert_not_nil assigns(:pages)
892 assert_not_nil assigns(:pages_by_date)
892 assert_not_nil assigns(:pages_by_date)
893
893
894 assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1'
894 assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1'
895 end
895 end
896
896
897 def test_not_found
897 def test_not_found
898 get :show, :project_id => 999
898 get :show, :project_id => 999
899 assert_response 404
899 assert_response 404
900 end
900 end
901
901
902 def test_protect_page
902 def test_protect_page
903 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
903 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
904 assert !page.protected?
904 assert !page.protected?
905 @request.session[:user_id] = 2
905 @request.session[:user_id] = 2
906 post :protect, :project_id => 1, :id => page.title, :protected => '1'
906 post :protect, :project_id => 1, :id => page.title, :protected => '1'
907 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
907 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
908 assert page.reload.protected?
908 assert page.reload.protected?
909 end
909 end
910
910
911 def test_unprotect_page
911 def test_unprotect_page
912 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
912 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
913 assert page.protected?
913 assert page.protected?
914 @request.session[:user_id] = 2
914 @request.session[:user_id] = 2
915 post :protect, :project_id => 1, :id => page.title, :protected => '0'
915 post :protect, :project_id => 1, :id => page.title, :protected => '0'
916 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
916 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
917 assert !page.reload.protected?
917 assert !page.reload.protected?
918 end
918 end
919
919
920 def test_show_page_with_edit_link
920 def test_show_page_with_edit_link
921 @request.session[:user_id] = 2
921 @request.session[:user_id] = 2
922 get :show, :project_id => 1
922 get :show, :project_id => 1
923 assert_response :success
923 assert_response :success
924 assert_template 'show'
924 assert_template 'show'
925 assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit'
925 assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit'
926 end
926 end
927
927
928 def test_show_page_without_edit_link
928 def test_show_page_without_edit_link
929 @request.session[:user_id] = 4
929 @request.session[:user_id] = 4
930 get :show, :project_id => 1
930 get :show, :project_id => 1
931 assert_response :success
931 assert_response :success
932 assert_template 'show'
932 assert_template 'show'
933 assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit', 0
933 assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit', 0
934 end
934 end
935
935
936 def test_show_pdf
936 def test_show_pdf
937 @request.session[:user_id] = 2
937 @request.session[:user_id] = 2
938 get :show, :project_id => 1, :format => 'pdf'
938 get :show, :project_id => 1, :format => 'pdf'
939 assert_response :success
939 assert_response :success
940 assert_not_nil assigns(:page)
940 assert_not_nil assigns(:page)
941 assert_equal 'application/pdf', @response.content_type
941 assert_equal 'application/pdf', @response.content_type
942 assert_equal 'attachment; filename="CookBook_documentation.pdf"',
942 assert_equal 'attachment; filename="CookBook_documentation.pdf"',
943 @response.headers['Content-Disposition']
943 @response.headers['Content-Disposition']
944 end
944 end
945
945
946 def test_show_html
946 def test_show_html
947 @request.session[:user_id] = 2
947 @request.session[:user_id] = 2
948 get :show, :project_id => 1, :format => 'html'
948 get :show, :project_id => 1, :format => 'html'
949 assert_response :success
949 assert_response :success
950 assert_not_nil assigns(:page)
950 assert_not_nil assigns(:page)
951 assert_equal 'text/html', @response.content_type
951 assert_equal 'text/html', @response.content_type
952 assert_equal 'attachment; filename="CookBook_documentation.html"',
952 assert_equal 'attachment; filename="CookBook_documentation.html"',
953 @response.headers['Content-Disposition']
953 @response.headers['Content-Disposition']
954 assert_select 'h1', :text => /CookBook documentation/
954 assert_select 'h1', :text => /CookBook documentation/
955 end
955 end
956
956
957 def test_show_versioned_html
957 def test_show_versioned_html
958 @request.session[:user_id] = 2
958 @request.session[:user_id] = 2
959 get :show, :project_id => 1, :format => 'html', :version => 2
959 get :show, :project_id => 1, :format => 'html', :version => 2
960 assert_response :success
960 assert_response :success
961 assert_not_nil assigns(:content)
961 assert_not_nil assigns(:content)
962 assert_equal 2, assigns(:content).version
962 assert_equal 2, assigns(:content).version
963 assert_equal 'text/html', @response.content_type
963 assert_equal 'text/html', @response.content_type
964 assert_equal 'attachment; filename="CookBook_documentation.html"',
964 assert_equal 'attachment; filename="CookBook_documentation.html"',
965 @response.headers['Content-Disposition']
965 @response.headers['Content-Disposition']
966 assert_select 'h1', :text => /CookBook documentation/
966 assert_select 'h1', :text => /CookBook documentation/
967 end
967 end
968
968
969 def test_show_txt
969 def test_show_txt
970 @request.session[:user_id] = 2
970 @request.session[:user_id] = 2
971 get :show, :project_id => 1, :format => 'txt'
971 get :show, :project_id => 1, :format => 'txt'
972 assert_response :success
972 assert_response :success
973 assert_not_nil assigns(:page)
973 assert_not_nil assigns(:page)
974 assert_equal 'text/plain', @response.content_type
974 assert_equal 'text/plain', @response.content_type
975 assert_equal 'attachment; filename="CookBook_documentation.txt"',
975 assert_equal 'attachment; filename="CookBook_documentation.txt"',
976 @response.headers['Content-Disposition']
976 @response.headers['Content-Disposition']
977 assert_include 'h1. CookBook documentation', @response.body
977 assert_include 'h1. CookBook documentation', @response.body
978 end
978 end
979
979
980 def test_show_versioned_txt
980 def test_show_versioned_txt
981 @request.session[:user_id] = 2
981 @request.session[:user_id] = 2
982 get :show, :project_id => 1, :format => 'txt', :version => 2
982 get :show, :project_id => 1, :format => 'txt', :version => 2
983 assert_response :success
983 assert_response :success
984 assert_not_nil assigns(:content)
984 assert_not_nil assigns(:content)
985 assert_equal 2, assigns(:content).version
985 assert_equal 2, assigns(:content).version
986 assert_equal 'text/plain', @response.content_type
986 assert_equal 'text/plain', @response.content_type
987 assert_equal 'attachment; filename="CookBook_documentation.txt"',
987 assert_equal 'attachment; filename="CookBook_documentation.txt"',
988 @response.headers['Content-Disposition']
988 @response.headers['Content-Disposition']
989 assert_include 'h1. CookBook documentation', @response.body
989 assert_include 'h1. CookBook documentation', @response.body
990 end
990 end
991
991
992 def test_edit_unprotected_page
992 def test_edit_unprotected_page
993 # Non members can edit unprotected wiki pages
993 # Non members can edit unprotected wiki pages
994 @request.session[:user_id] = 4
994 @request.session[:user_id] = 4
995 get :edit, :project_id => 1, :id => 'Another_page'
995 get :edit, :project_id => 1, :id => 'Another_page'
996 assert_response :success
996 assert_response :success
997 assert_template 'edit'
997 assert_template 'edit'
998 end
998 end
999
999
1000 def test_edit_protected_page_by_nonmember
1000 def test_edit_protected_page_by_nonmember
1001 # Non members cannot edit protected wiki pages
1001 # Non members cannot edit protected wiki pages
1002 @request.session[:user_id] = 4
1002 @request.session[:user_id] = 4
1003 get :edit, :project_id => 1, :id => 'CookBook_documentation'
1003 get :edit, :project_id => 1, :id => 'CookBook_documentation'
1004 assert_response 403
1004 assert_response 403
1005 end
1005 end
1006
1006
1007 def test_edit_protected_page_by_member
1007 def test_edit_protected_page_by_member
1008 @request.session[:user_id] = 2
1008 @request.session[:user_id] = 2
1009 get :edit, :project_id => 1, :id => 'CookBook_documentation'
1009 get :edit, :project_id => 1, :id => 'CookBook_documentation'
1010 assert_response :success
1010 assert_response :success
1011 assert_template 'edit'
1011 assert_template 'edit'
1012 end
1012 end
1013
1013
1014 def test_history_of_non_existing_page_should_return_404
1014 def test_history_of_non_existing_page_should_return_404
1015 get :history, :project_id => 1, :id => 'Unknown_page'
1015 get :history, :project_id => 1, :id => 'Unknown_page'
1016 assert_response 404
1016 assert_response 404
1017 end
1017 end
1018
1018
1019 def test_add_attachment
1019 def test_add_attachment
1020 @request.session[:user_id] = 2
1020 @request.session[:user_id] = 2
1021 assert_difference 'Attachment.count' do
1021 assert_difference 'Attachment.count' do
1022 post :add_attachment, :project_id => 1, :id => 'CookBook_documentation',
1022 post :add_attachment, :project_id => 1, :id => 'CookBook_documentation',
1023 :attachments => {
1023 :attachments => {
1024 '1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'),
1024 '1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'),
1025 'description' => 'test file'}
1025 'description' => 'test file'}
1026 }
1026 }
1027 end
1027 end
1028 attachment = Attachment.order('id DESC').first
1028 attachment = Attachment.order('id DESC').first
1029 assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container
1029 assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container
1030 end
1030 end
1031 end
1031 end
General Comments 0
You need to be logged in to leave comments. Login now