@@ -1,521 +1,521 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 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.expand_path('../../test_helper', __FILE__) |
|
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/ | |
39 |
|
39 | |||
40 | # child_pages macro |
|
40 | # child_pages macro | |
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 |
|
58 | def test_show_redirected_page | |
59 | WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page') |
|
59 | WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page') | |
60 |
|
60 | |||
61 | get :show, :project_id => 'ecookbook', :id => 'Old_title' |
|
61 | get :show, :project_id => 'ecookbook', :id => 'Old_title' | |
62 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
62 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | def test_show_with_sidebar |
|
65 | def test_show_with_sidebar | |
66 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') |
|
66 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') | |
67 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') |
|
67 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') | |
68 | page.save! |
|
68 | page.save! | |
69 |
|
69 | |||
70 | get :show, :project_id => 1, :id => 'Another_page' |
|
70 | get :show, :project_id => 1, :id => 'Another_page' | |
71 | assert_response :success |
|
71 | assert_response :success | |
72 | assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, |
|
72 | assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, | |
73 | :content => /Side bar content for test_show_with_sidebar/ |
|
73 | :content => /Side bar content for test_show_with_sidebar/ | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def test_show_unexistent_page_without_edit_right |
|
76 | def test_show_unexistent_page_without_edit_right | |
77 | get :show, :project_id => 1, :id => 'Unexistent page' |
|
77 | get :show, :project_id => 1, :id => 'Unexistent page' | |
78 | assert_response 404 |
|
78 | assert_response 404 | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_show_unexistent_page_with_edit_right |
|
81 | def test_show_unexistent_page_with_edit_right | |
82 | @request.session[:user_id] = 2 |
|
82 | @request.session[:user_id] = 2 | |
83 | get :show, :project_id => 1, :id => 'Unexistent page' |
|
83 | get :show, :project_id => 1, :id => 'Unexistent page' | |
84 | assert_response :success |
|
84 | assert_response :success | |
85 | assert_template 'edit' |
|
85 | assert_template 'edit' | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | def test_create_page |
|
88 | def test_create_page | |
89 | @request.session[:user_id] = 2 |
|
89 | @request.session[:user_id] = 2 | |
90 | put :update, :project_id => 1, |
|
90 | put :update, :project_id => 1, | |
91 | :id => 'New page', |
|
91 | :id => 'New page', | |
92 | :content => {:comments => 'Created the page', |
|
92 | :content => {:comments => 'Created the page', | |
93 | :text => "h1. New page\n\nThis is a new page", |
|
93 | :text => "h1. New page\n\nThis is a new page", | |
94 | :version => 0} |
|
94 | :version => 0} | |
95 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' |
|
95 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' | |
96 | page = Project.find(1).wiki.find_page('New page') |
|
96 | page = Project.find(1).wiki.find_page('New page') | |
97 | assert !page.new_record? |
|
97 | assert !page.new_record? | |
98 | assert_not_nil page.content |
|
98 | assert_not_nil page.content | |
99 | assert_equal 'Created the page', page.content.comments |
|
99 | assert_equal 'Created the page', page.content.comments | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | def test_create_page_with_attachments |
|
102 | def test_create_page_with_attachments | |
103 | @request.session[:user_id] = 2 |
|
103 | @request.session[:user_id] = 2 | |
104 | assert_difference 'WikiPage.count' do |
|
104 | assert_difference 'WikiPage.count' do | |
105 | assert_difference 'Attachment.count' do |
|
105 | assert_difference 'Attachment.count' do | |
106 | put :update, :project_id => 1, |
|
106 | put :update, :project_id => 1, | |
107 | :id => 'New page', |
|
107 | :id => 'New page', | |
108 | :content => {:comments => 'Created the page', |
|
108 | :content => {:comments => 'Created the page', | |
109 | :text => "h1. New page\n\nThis is a new page", |
|
109 | :text => "h1. New page\n\nThis is a new page", | |
110 | :version => 0}, |
|
110 | :version => 0}, | |
111 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
111 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
112 | end |
|
112 | end | |
113 | end |
|
113 | end | |
114 | page = Project.find(1).wiki.find_page('New page') |
|
114 | page = Project.find(1).wiki.find_page('New page') | |
115 | assert_equal 1, page.attachments.count |
|
115 | assert_equal 1, page.attachments.count | |
116 | assert_equal 'testfile.txt', page.attachments.first.filename |
|
116 | assert_equal 'testfile.txt', page.attachments.first.filename | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def test_update_page |
|
119 | def test_update_page | |
120 | @request.session[:user_id] = 2 |
|
120 | @request.session[:user_id] = 2 | |
121 | assert_no_difference 'WikiPage.count' do |
|
121 | assert_no_difference 'WikiPage.count' do | |
122 | assert_no_difference 'WikiContent.count' do |
|
122 | assert_no_difference 'WikiContent.count' do | |
123 | assert_difference 'WikiContent::Version.count' do |
|
123 | assert_difference 'WikiContent::Version.count' do | |
124 | put :update, :project_id => 1, |
|
124 | put :update, :project_id => 1, | |
125 | :id => 'Another_page', |
|
125 | :id => 'Another_page', | |
126 | :content => { |
|
126 | :content => { | |
127 | :comments => "my comments", |
|
127 | :comments => "my comments", | |
128 | :text => "edited", |
|
128 | :text => "edited", | |
129 | :version => 1 |
|
129 | :version => 1 | |
130 | } |
|
130 | } | |
131 | end |
|
131 | end | |
132 | end |
|
132 | end | |
133 | end |
|
133 | end | |
134 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
134 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' | |
135 |
|
135 | |||
136 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
136 | page = Wiki.find(1).pages.find_by_title('Another_page') | |
137 | assert_equal "edited", page.content.text |
|
137 | assert_equal "edited", page.content.text | |
138 | assert_equal 2, page.content.version |
|
138 | assert_equal 2, page.content.version | |
139 | assert_equal "my comments", page.content.comments |
|
139 | assert_equal "my comments", page.content.comments | |
140 | end |
|
140 | end | |
141 |
|
141 | |||
142 | def test_update_page_with_failure |
|
142 | def test_update_page_with_failure | |
143 | @request.session[:user_id] = 2 |
|
143 | @request.session[:user_id] = 2 | |
144 | assert_no_difference 'WikiPage.count' do |
|
144 | assert_no_difference 'WikiPage.count' do | |
145 | assert_no_difference 'WikiContent.count' do |
|
145 | assert_no_difference 'WikiContent.count' do | |
146 | assert_no_difference 'WikiContent::Version.count' do |
|
146 | assert_no_difference 'WikiContent::Version.count' do | |
147 | put :update, :project_id => 1, |
|
147 | put :update, :project_id => 1, | |
148 | :id => 'Another_page', |
|
148 | :id => 'Another_page', | |
149 | :content => { |
|
149 | :content => { | |
150 | :comments => 'a' * 300, # failure here, comment is too long |
|
150 | :comments => 'a' * 300, # failure here, comment is too long | |
151 | :text => 'edited', |
|
151 | :text => 'edited', | |
152 | :version => 1 |
|
152 | :version => 1 | |
153 | } |
|
153 | } | |
154 | end |
|
154 | end | |
155 | end |
|
155 | end | |
156 | end |
|
156 | end | |
157 | assert_response :success |
|
157 | assert_response :success | |
158 | assert_template 'edit' |
|
158 | assert_template 'edit' | |
159 |
|
159 | |||
160 | assert_error_tag :descendant => {:content => /Comment is too long/} |
|
160 | assert_error_tag :descendant => {:content => /Comment is too long/} | |
161 | assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited' |
|
161 | assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited' | |
162 | assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'} |
|
162 | assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'} | |
163 | end |
|
163 | end | |
164 |
|
164 | |||
165 | def test_update_stale_page_should_not_raise_an_error |
|
165 | def test_update_stale_page_should_not_raise_an_error | |
166 | @request.session[:user_id] = 2 |
|
166 | @request.session[:user_id] = 2 | |
167 | c = Wiki.find(1).find_page('Another_page').content |
|
167 | c = Wiki.find(1).find_page('Another_page').content | |
168 | c.text = 'Previous text' |
|
168 | c.text = 'Previous text' | |
169 | c.save! |
|
169 | c.save! | |
170 | assert_equal 2, c.version |
|
170 | assert_equal 2, c.version | |
171 |
|
171 | |||
172 | assert_no_difference 'WikiPage.count' do |
|
172 | assert_no_difference 'WikiPage.count' do | |
173 | assert_no_difference 'WikiContent.count' do |
|
173 | assert_no_difference 'WikiContent.count' do | |
174 | assert_no_difference 'WikiContent::Version.count' do |
|
174 | assert_no_difference 'WikiContent::Version.count' do | |
175 | put :update, :project_id => 1, |
|
175 | put :update, :project_id => 1, | |
176 | :id => 'Another_page', |
|
176 | :id => 'Another_page', | |
177 | :content => { |
|
177 | :content => { | |
178 | :comments => 'My comments', |
|
178 | :comments => 'My comments', | |
179 | :text => 'Text should not be lost', |
|
179 | :text => 'Text should not be lost', | |
180 | :version => 1 |
|
180 | :version => 1 | |
181 | } |
|
181 | } | |
182 | end |
|
182 | end | |
183 | end |
|
183 | end | |
184 | end |
|
184 | end | |
185 | assert_response :success |
|
185 | assert_response :success | |
186 | assert_template 'edit' |
|
186 | assert_template 'edit' | |
187 | assert_tag :div, |
|
187 | assert_tag :div, | |
188 | :attributes => { :class => /error/ }, |
|
188 | :attributes => { :class => /error/ }, | |
189 | :content => /Data has been updated by another user/ |
|
189 | :content => /Data has been updated by another user/ | |
190 | assert_tag 'textarea', |
|
190 | assert_tag 'textarea', | |
191 | :attributes => { :name => 'content[text]' }, |
|
191 | :attributes => { :name => 'content[text]' }, | |
192 | :content => /Text should not be lost/ |
|
192 | :content => /Text should not be lost/ | |
193 | assert_tag 'input', |
|
193 | assert_tag 'input', | |
194 | :attributes => { :name => 'content[comments]', :value => 'My comments' } |
|
194 | :attributes => { :name => 'content[comments]', :value => 'My comments' } | |
195 |
|
195 | |||
196 | c.reload |
|
196 | c.reload | |
197 | assert_equal 'Previous text', c.text |
|
197 | assert_equal 'Previous text', c.text | |
198 | assert_equal 2, c.version |
|
198 | assert_equal 2, c.version | |
199 | end |
|
199 | end | |
200 |
|
200 | |||
201 | def test_preview |
|
201 | def test_preview | |
202 | @request.session[:user_id] = 2 |
|
202 | @request.session[:user_id] = 2 | |
203 | xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', |
|
203 | xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', | |
204 | :content => { :comments => '', |
|
204 | :content => { :comments => '', | |
205 | :text => 'this is a *previewed text*', |
|
205 | :text => 'this is a *previewed text*', | |
206 | :version => 3 } |
|
206 | :version => 3 } | |
207 | assert_response :success |
|
207 | assert_response :success | |
208 | assert_template 'common/_preview' |
|
208 | assert_template 'common/_preview' | |
209 | assert_tag :tag => 'strong', :content => /previewed text/ |
|
209 | assert_tag :tag => 'strong', :content => /previewed text/ | |
210 | end |
|
210 | end | |
211 |
|
211 | |||
212 | def test_preview_new_page |
|
212 | def test_preview_new_page | |
213 | @request.session[:user_id] = 2 |
|
213 | @request.session[:user_id] = 2 | |
214 | xhr :post, :preview, :project_id => 1, :id => 'New page', |
|
214 | xhr :post, :preview, :project_id => 1, :id => 'New page', | |
215 | :content => { :text => 'h1. New page', |
|
215 | :content => { :text => 'h1. New page', | |
216 | :comments => '', |
|
216 | :comments => '', | |
217 | :version => 0 } |
|
217 | :version => 0 } | |
218 | assert_response :success |
|
218 | assert_response :success | |
219 | assert_template 'common/_preview' |
|
219 | assert_template 'common/_preview' | |
220 | assert_tag :tag => 'h1', :content => /New page/ |
|
220 | assert_tag :tag => 'h1', :content => /New page/ | |
221 | end |
|
221 | end | |
222 |
|
222 | |||
223 | def test_history |
|
223 | def test_history | |
224 | get :history, :project_id => 1, :id => 'CookBook_documentation' |
|
224 | get :history, :project_id => 1, :id => 'CookBook_documentation' | |
225 | assert_response :success |
|
225 | assert_response :success | |
226 | assert_template 'history' |
|
226 | assert_template 'history' | |
227 | assert_not_nil assigns(:versions) |
|
227 | assert_not_nil assigns(:versions) | |
228 | assert_equal 3, assigns(:versions).size |
|
228 | assert_equal 3, assigns(:versions).size | |
229 | assert_select "input[type=submit][name=commit]" |
|
229 | assert_select "input[type=submit][name=commit]" | |
230 | end |
|
230 | end | |
231 |
|
231 | |||
232 | def test_history_with_one_version |
|
232 | def test_history_with_one_version | |
233 | get :history, :project_id => 1, :id => 'Another_page' |
|
233 | get :history, :project_id => 1, :id => 'Another_page' | |
234 | assert_response :success |
|
234 | assert_response :success | |
235 | assert_template 'history' |
|
235 | assert_template 'history' | |
236 | assert_not_nil assigns(:versions) |
|
236 | assert_not_nil assigns(:versions) | |
237 | assert_equal 1, assigns(:versions).size |
|
237 | assert_equal 1, assigns(:versions).size | |
238 | assert_select "input[type=submit][name=commit]", false |
|
238 | assert_select "input[type=submit][name=commit]", false | |
239 | end |
|
239 | end | |
240 |
|
240 | |||
241 | def test_diff |
|
241 | def test_diff | |
242 | 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 | |
243 | assert_response :success |
|
243 | assert_response :success | |
244 | assert_template 'diff' |
|
244 | assert_template 'diff' | |
245 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, |
|
245 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, | |
246 | :content => /updated/ |
|
246 | :content => /updated/ | |
247 | end |
|
247 | end | |
248 |
|
248 | |||
249 | def test_annotate |
|
249 | def test_annotate | |
250 | get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 |
|
250 | get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 | |
251 | assert_response :success |
|
251 | assert_response :success | |
252 | assert_template 'annotate' |
|
252 | assert_template 'annotate' | |
253 |
|
253 | |||
254 | # Line 1 |
|
254 | # Line 1 | |
255 | assert_tag :tag => 'tr', :child => { |
|
255 | assert_tag :tag => 'tr', :child => { | |
256 | :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => { |
|
256 | :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => { | |
257 | :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => { |
|
257 | :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => { | |
258 | :tag => 'td', :content => /h1\. CookBook documentation/ |
|
258 | :tag => 'td', :content => /h1\. CookBook documentation/ | |
259 | } |
|
259 | } | |
260 | } |
|
260 | } | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | # Line 5 |
|
263 | # Line 5 | |
264 | assert_tag :tag => 'tr', :child => { |
|
264 | assert_tag :tag => 'tr', :child => { | |
265 | :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => { |
|
265 | :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => { | |
266 | :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => { |
|
266 | :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => { | |
267 | :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ |
|
267 | :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ | |
268 | } |
|
268 | } | |
269 | } |
|
269 | } | |
270 | } |
|
270 | } | |
271 | end |
|
271 | end | |
272 |
|
272 | |||
273 | def test_get_rename |
|
273 | def test_get_rename | |
274 | @request.session[:user_id] = 2 |
|
274 | @request.session[:user_id] = 2 | |
275 | get :rename, :project_id => 1, :id => 'Another_page' |
|
275 | get :rename, :project_id => 1, :id => 'Another_page' | |
276 | assert_response :success |
|
276 | assert_response :success | |
277 | assert_template 'rename' |
|
277 | assert_template 'rename' | |
278 | assert_tag 'option', |
|
278 | assert_tag 'option', | |
279 | :attributes => {:value => ''}, |
|
279 | :attributes => {:value => ''}, | |
280 | :content => '', |
|
280 | :content => '', | |
281 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
|
281 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} | |
282 | assert_no_tag 'option', |
|
282 | assert_no_tag 'option', | |
283 | :attributes => {:selected => 'selected'}, |
|
283 | :attributes => {:selected => 'selected'}, | |
284 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
|
284 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} | |
285 | end |
|
285 | end | |
286 |
|
286 | |||
287 | def test_get_rename_child_page |
|
287 | def test_get_rename_child_page | |
288 | @request.session[:user_id] = 2 |
|
288 | @request.session[:user_id] = 2 | |
289 | get :rename, :project_id => 1, :id => 'Child_1' |
|
289 | get :rename, :project_id => 1, :id => 'Child_1' | |
290 | assert_response :success |
|
290 | assert_response :success | |
291 | assert_template 'rename' |
|
291 | assert_template 'rename' | |
292 | assert_tag 'option', |
|
292 | assert_tag 'option', | |
293 | :attributes => {:value => ''}, |
|
293 | :attributes => {:value => ''}, | |
294 | :content => '', |
|
294 | :content => '', | |
295 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
|
295 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} | |
296 | assert_tag 'option', |
|
296 | assert_tag 'option', | |
297 | :attributes => {:value => '2', :selected => 'selected'}, |
|
297 | :attributes => {:value => '2', :selected => 'selected'}, | |
298 | :content => /Another page/, |
|
298 | :content => /Another page/, | |
299 | :parent => { |
|
299 | :parent => { | |
300 | :tag => 'select', |
|
300 | :tag => 'select', | |
301 | :attributes => {:name => 'wiki_page[parent_id]'} |
|
301 | :attributes => {:name => 'wiki_page[parent_id]'} | |
302 | } |
|
302 | } | |
303 | end |
|
303 | end | |
304 |
|
304 | |||
305 | def test_rename_with_redirect |
|
305 | def test_rename_with_redirect | |
306 | @request.session[:user_id] = 2 |
|
306 | @request.session[:user_id] = 2 | |
307 | post :rename, :project_id => 1, :id => 'Another_page', |
|
307 | post :rename, :project_id => 1, :id => 'Another_page', | |
308 | :wiki_page => { :title => 'Another renamed page', |
|
308 | :wiki_page => { :title => 'Another renamed page', | |
309 | :redirect_existing_links => 1 } |
|
309 | :redirect_existing_links => 1 } | |
310 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
|
310 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' | |
311 | wiki = Project.find(1).wiki |
|
311 | wiki = Project.find(1).wiki | |
312 | # Check redirects |
|
312 | # Check redirects | |
313 | assert_not_nil wiki.find_page('Another page') |
|
313 | assert_not_nil wiki.find_page('Another page') | |
314 | assert_nil wiki.find_page('Another page', :with_redirect => false) |
|
314 | assert_nil wiki.find_page('Another page', :with_redirect => false) | |
315 | end |
|
315 | end | |
316 |
|
316 | |||
317 | def test_rename_without_redirect |
|
317 | def test_rename_without_redirect | |
318 | @request.session[:user_id] = 2 |
|
318 | @request.session[:user_id] = 2 | |
319 | post :rename, :project_id => 1, :id => 'Another_page', |
|
319 | post :rename, :project_id => 1, :id => 'Another_page', | |
320 | :wiki_page => { :title => 'Another renamed page', |
|
320 | :wiki_page => { :title => 'Another renamed page', | |
321 | :redirect_existing_links => "0" } |
|
321 | :redirect_existing_links => "0" } | |
322 | 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' | |
323 | wiki = Project.find(1).wiki |
|
323 | wiki = Project.find(1).wiki | |
324 | # Check that there's no redirects |
|
324 | # Check that there's no redirects | |
325 | assert_nil wiki.find_page('Another page') |
|
325 | assert_nil wiki.find_page('Another page') | |
326 | end |
|
326 | end | |
327 |
|
327 | |||
328 | def test_rename_with_parent_assignment |
|
328 | def test_rename_with_parent_assignment | |
329 | @request.session[:user_id] = 2 |
|
329 | @request.session[:user_id] = 2 | |
330 | post :rename, :project_id => 1, :id => 'Another_page', |
|
330 | post :rename, :project_id => 1, :id => 'Another_page', | |
331 | :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' } | |
332 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
|
332 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' | |
333 | assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent |
|
333 | assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent | |
334 | end |
|
334 | end | |
335 |
|
335 | |||
336 | def test_rename_with_parent_unassignment |
|
336 | def test_rename_with_parent_unassignment | |
337 | @request.session[:user_id] = 2 |
|
337 | @request.session[:user_id] = 2 | |
338 | post :rename, :project_id => 1, :id => 'Child_1', |
|
338 | post :rename, :project_id => 1, :id => 'Child_1', | |
339 | :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' } |
|
339 | :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' } | |
340 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' |
|
340 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' | |
341 | assert_nil WikiPage.find_by_title('Child_1').parent |
|
341 | assert_nil WikiPage.find_by_title('Child_1').parent | |
342 | end |
|
342 | end | |
343 |
|
343 | |||
344 | def test_destroy_child |
|
344 | def test_destroy_child | |
345 | @request.session[:user_id] = 2 |
|
345 | @request.session[:user_id] = 2 | |
346 | delete :destroy, :project_id => 1, :id => 'Child_1' |
|
346 | delete :destroy, :project_id => 1, :id => 'Child_1' | |
347 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
347 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
348 | end |
|
348 | end | |
349 |
|
349 | |||
350 | def test_destroy_parent |
|
350 | def test_destroy_parent | |
351 | @request.session[:user_id] = 2 |
|
351 | @request.session[:user_id] = 2 | |
352 | assert_no_difference('WikiPage.count') do |
|
352 | assert_no_difference('WikiPage.count') do | |
353 | delete :destroy, :project_id => 1, :id => 'Another_page' |
|
353 | delete :destroy, :project_id => 1, :id => 'Another_page' | |
354 | end |
|
354 | end | |
355 | assert_response :success |
|
355 | assert_response :success | |
356 | assert_template 'destroy' |
|
356 | assert_template 'destroy' | |
357 | end |
|
357 | end | |
358 |
|
358 | |||
359 | def test_destroy_parent_with_nullify |
|
359 | def test_destroy_parent_with_nullify | |
360 | @request.session[:user_id] = 2 |
|
360 | @request.session[:user_id] = 2 | |
361 | assert_difference('WikiPage.count', -1) do |
|
361 | assert_difference('WikiPage.count', -1) do | |
362 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify' |
|
362 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify' | |
363 | end |
|
363 | end | |
364 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
364 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
365 | assert_nil WikiPage.find_by_id(2) |
|
365 | assert_nil WikiPage.find_by_id(2) | |
366 | end |
|
366 | end | |
367 |
|
367 | |||
368 | def test_destroy_parent_with_cascade |
|
368 | def test_destroy_parent_with_cascade | |
369 | @request.session[:user_id] = 2 |
|
369 | @request.session[:user_id] = 2 | |
370 | assert_difference('WikiPage.count', -3) do |
|
370 | assert_difference('WikiPage.count', -3) do | |
371 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy' |
|
371 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy' | |
372 | end |
|
372 | end | |
373 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
373 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
374 | assert_nil WikiPage.find_by_id(2) |
|
374 | assert_nil WikiPage.find_by_id(2) | |
375 | assert_nil WikiPage.find_by_id(5) |
|
375 | assert_nil WikiPage.find_by_id(5) | |
376 | end |
|
376 | end | |
377 |
|
377 | |||
378 | def test_destroy_parent_with_reassign |
|
378 | def test_destroy_parent_with_reassign | |
379 | @request.session[:user_id] = 2 |
|
379 | @request.session[:user_id] = 2 | |
380 | assert_difference('WikiPage.count', -1) do |
|
380 | assert_difference('WikiPage.count', -1) do | |
381 | 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 | |
382 | end |
|
382 | end | |
383 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
383 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
384 | assert_nil WikiPage.find_by_id(2) |
|
384 | assert_nil WikiPage.find_by_id(2) | |
385 | assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent |
|
385 | assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent | |
386 | end |
|
386 | end | |
387 |
|
387 | |||
388 | def test_index |
|
388 | def test_index | |
389 | get :index, :project_id => 'ecookbook' |
|
389 | get :index, :project_id => 'ecookbook' | |
390 | assert_response :success |
|
390 | assert_response :success | |
391 | assert_template 'index' |
|
391 | assert_template 'index' | |
392 | pages = assigns(:pages) |
|
392 | pages = assigns(:pages) | |
393 | assert_not_nil pages |
|
393 | assert_not_nil pages | |
394 | assert_equal Project.find(1).wiki.pages.size, pages.size |
|
394 | assert_equal Project.find(1).wiki.pages.size, pages.size | |
395 | assert_equal pages.first.content.updated_on, pages.first.updated_on |
|
395 | assert_equal pages.first.content.updated_on, pages.first.updated_on | |
396 |
|
396 | |||
397 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
|
397 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, | |
398 | :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' }, | |
399 | :content => 'CookBook documentation' }, |
|
399 | :content => 'CookBook documentation' }, | |
400 | :child => { :tag => 'ul', |
|
400 | :child => { :tag => 'ul', | |
401 | :child => { :tag => 'li', |
|
401 | :child => { :tag => 'li', | |
402 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, |
|
402 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, | |
403 | :content => 'Page with an inline image' } } } }, |
|
403 | :content => 'Page with an inline image' } } } }, | |
404 | :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' }, | |
405 | :content => 'Another page' } } |
|
405 | :content => 'Another page' } } | |
406 | end |
|
406 | end | |
407 |
|
407 | |||
408 | def test_index_should_include_atom_link |
|
408 | def test_index_should_include_atom_link | |
409 | get :index, :project_id => 'ecookbook' |
|
409 | get :index, :project_id => 'ecookbook' | |
410 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} |
|
410 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} | |
411 | end |
|
411 | end | |
412 |
|
412 | |||
413 | context "GET :export" do |
|
413 | context "GET :export" do | |
414 | context "with an authorized user to export the wiki" do |
|
414 | context "with an authorized user to export the wiki" do | |
415 | setup do |
|
415 | setup do | |
416 | @request.session[:user_id] = 2 |
|
416 | @request.session[:user_id] = 2 | |
417 | get :export, :project_id => 'ecookbook' |
|
417 | get :export, :project_id => 'ecookbook' | |
418 | end |
|
418 | end | |
419 |
|
419 | |||
420 | should_respond_with :success |
|
420 | should_respond_with :success | |
421 | should_assign_to :pages |
|
421 | should_assign_to :pages | |
422 | should_respond_with_content_type "text/html" |
|
422 | should_respond_with_content_type "text/html" | |
423 | 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 | |
424 | assert_select "a[name=?]", "CookBook_documentation" |
|
424 | assert_select "a[name=?]", "CookBook_documentation" | |
425 | assert_select "a[name=?]", "Another_page" |
|
425 | assert_select "a[name=?]", "Another_page" | |
426 | assert_select "a[name=?]", "Page_with_an_inline_image" |
|
426 | assert_select "a[name=?]", "Page_with_an_inline_image" | |
427 | end |
|
427 | end | |
428 |
|
428 | |||
429 | end |
|
429 | end | |
430 |
|
430 | |||
431 | context "with an unauthorized user" do |
|
431 | context "with an unauthorized user" do | |
432 | setup do |
|
432 | setup do | |
433 | get :export, :project_id => 'ecookbook' |
|
433 | get :export, :project_id => 'ecookbook' | |
434 |
|
434 | |||
435 | should_respond_with :redirect |
|
435 | should_respond_with :redirect | |
436 | should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} } |
|
436 | should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} } | |
437 | end |
|
437 | end | |
438 | end |
|
438 | end | |
439 | end |
|
439 | end | |
440 |
|
440 | |||
441 | context "GET :date_index" do |
|
441 | context "GET :date_index" do | |
442 | setup do |
|
442 | setup do | |
443 | get :date_index, :project_id => 'ecookbook' |
|
443 | get :date_index, :project_id => 'ecookbook' | |
444 | end |
|
444 | end | |
445 |
|
445 | |||
446 | should_respond_with :success |
|
446 | should_respond_with :success | |
447 | should_assign_to :pages |
|
447 | should_assign_to :pages | |
448 | should_assign_to :pages_by_date |
|
448 | should_assign_to :pages_by_date | |
449 | should_render_template 'wiki/date_index' |
|
449 | should_render_template 'wiki/date_index' | |
450 |
|
450 | |||
451 | should "include atom link" do |
|
451 | should "include atom link" do | |
452 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} |
|
452 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} | |
453 | end |
|
453 | end | |
454 | end |
|
454 | end | |
455 |
|
455 | |||
456 | def test_not_found |
|
456 | def test_not_found | |
457 | get :show, :project_id => 999 |
|
457 | get :show, :project_id => 999 | |
458 | assert_response 404 |
|
458 | assert_response 404 | |
459 | end |
|
459 | end | |
460 |
|
460 | |||
461 | def test_protect_page |
|
461 | def test_protect_page | |
462 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') |
|
462 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') | |
463 | assert !page.protected? |
|
463 | assert !page.protected? | |
464 | @request.session[:user_id] = 2 |
|
464 | @request.session[:user_id] = 2 | |
465 | post :protect, :project_id => 1, :id => page.title, :protected => '1' |
|
465 | post :protect, :project_id => 1, :id => page.title, :protected => '1' | |
466 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
|
466 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' | |
467 | assert page.reload.protected? |
|
467 | assert page.reload.protected? | |
468 | end |
|
468 | end | |
469 |
|
469 | |||
470 | def test_unprotect_page |
|
470 | def test_unprotect_page | |
471 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') |
|
471 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') | |
472 | assert page.protected? |
|
472 | assert page.protected? | |
473 | @request.session[:user_id] = 2 |
|
473 | @request.session[:user_id] = 2 | |
474 | post :protect, :project_id => 1, :id => page.title, :protected => '0' |
|
474 | post :protect, :project_id => 1, :id => page.title, :protected => '0' | |
475 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' |
|
475 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' | |
476 | assert !page.reload.protected? |
|
476 | assert !page.reload.protected? | |
477 | end |
|
477 | end | |
478 |
|
478 | |||
479 | def test_show_page_with_edit_link |
|
479 | def test_show_page_with_edit_link | |
480 | @request.session[:user_id] = 2 |
|
480 | @request.session[:user_id] = 2 | |
481 | get :show, :project_id => 1 |
|
481 | get :show, :project_id => 1 | |
482 | assert_response :success |
|
482 | assert_response :success | |
483 | assert_template 'show' |
|
483 | assert_template 'show' | |
484 | 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' } | |
485 | end |
|
485 | end | |
486 |
|
486 | |||
487 | def test_show_page_without_edit_link |
|
487 | def test_show_page_without_edit_link | |
488 | @request.session[:user_id] = 4 |
|
488 | @request.session[:user_id] = 4 | |
489 | get :show, :project_id => 1 |
|
489 | get :show, :project_id => 1 | |
490 | assert_response :success |
|
490 | assert_response :success | |
491 | assert_template 'show' |
|
491 | assert_template 'show' | |
492 | 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' } | |
493 | end |
|
493 | end | |
494 |
|
494 | |||
495 | def test_edit_unprotected_page |
|
495 | def test_edit_unprotected_page | |
496 | # Non members can edit unprotected wiki pages |
|
496 | # Non members can edit unprotected wiki pages | |
497 | @request.session[:user_id] = 4 |
|
497 | @request.session[:user_id] = 4 | |
498 | get :edit, :project_id => 1, :id => 'Another_page' |
|
498 | get :edit, :project_id => 1, :id => 'Another_page' | |
499 | assert_response :success |
|
499 | assert_response :success | |
500 | assert_template 'edit' |
|
500 | assert_template 'edit' | |
501 | end |
|
501 | end | |
502 |
|
502 | |||
503 | def test_edit_protected_page_by_nonmember |
|
503 | def test_edit_protected_page_by_nonmember | |
504 | # Non members can't edit protected wiki pages |
|
504 | # Non members can't edit protected wiki pages | |
505 | @request.session[:user_id] = 4 |
|
505 | @request.session[:user_id] = 4 | |
506 | get :edit, :project_id => 1, :id => 'CookBook_documentation' |
|
506 | get :edit, :project_id => 1, :id => 'CookBook_documentation' | |
507 | assert_response 403 |
|
507 | assert_response 403 | |
508 | end |
|
508 | end | |
509 |
|
509 | |||
510 | def test_edit_protected_page_by_member |
|
510 | def test_edit_protected_page_by_member | |
511 | @request.session[:user_id] = 2 |
|
511 | @request.session[:user_id] = 2 | |
512 | get :edit, :project_id => 1, :id => 'CookBook_documentation' |
|
512 | get :edit, :project_id => 1, :id => 'CookBook_documentation' | |
513 | assert_response :success |
|
513 | assert_response :success | |
514 | assert_template 'edit' |
|
514 | assert_template 'edit' | |
515 | end |
|
515 | end | |
516 |
|
516 | |||
517 | def test_history_of_non_existing_page_should_return_404 |
|
517 | def test_history_of_non_existing_page_should_return_404 | |
518 | get :history, :project_id => 1, :id => 'Unknown_page' |
|
518 | get :history, :project_id => 1, :id => 'Unknown_page' | |
519 | assert_response 404 |
|
519 | assert_response 404 | |
520 | end |
|
520 | end | |
521 | end |
|
521 | end |
General Comments 0
You need to be logged in to leave comments.
Login now