##// END OF EJS Templates
Adds functional tests....
Jean-Philippe Lang -
r8828:c49ef8e543c4
parent child
Show More
@@ -1,308 +1,313
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2011 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require File.expand_path('../../test_helper', __FILE__)
21 21 require 'attachments_controller'
22 22
23 23 # Re-raise errors caught by the controller.
24 24 class AttachmentsController; def rescue_action(e) raise e end; end
25 25
26 26 class AttachmentsControllerTest < ActionController::TestCase
27 27 fixtures :users, :projects, :roles, :members, :member_roles,
28 28 :enabled_modules, :issues, :trackers, :attachments,
29 29 :versions, :wiki_pages, :wikis, :documents
30 30
31 31 def setup
32 32 @controller = AttachmentsController.new
33 33 @request = ActionController::TestRequest.new
34 34 @response = ActionController::TestResponse.new
35 35 User.current = nil
36 36 set_fixtures_attachments_directory
37 37 end
38 38
39 39 def teardown
40 40 set_tmp_attachments_directory
41 41 end
42 42
43 43 def test_show_diff
44 44 ['inline', 'sbs'].each do |dt|
45 45 # 060719210727_changeset_utf8.diff
46 46 get :show, :id => 14, :type => dt
47 47 assert_response :success
48 48 assert_template 'diff'
49 49 assert_equal 'text/html', @response.content_type
50 50 assert_tag 'th',
51 51 :attributes => {:class => /filename/},
52 52 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
53 53 assert_tag 'td',
54 54 :attributes => {:class => /line-code/},
55 55 :content => /Demande créée avec succès/
56 56 end
57 57 set_tmp_attachments_directory
58 58 end
59 59
60 60 def test_show_diff_replcace_cannot_convert_content
61 61 with_settings :repositories_encodings => 'UTF-8' do
62 62 ['inline', 'sbs'].each do |dt|
63 63 # 060719210727_changeset_iso8859-1.diff
64 64 get :show, :id => 5, :type => dt
65 65 assert_response :success
66 66 assert_template 'diff'
67 67 assert_equal 'text/html', @response.content_type
68 68 assert_tag 'th',
69 69 :attributes => {:class => "filename"},
70 70 :content => /issues_controller.rb\t\(r\?vision 1484\)/
71 71 assert_tag 'td',
72 72 :attributes => {:class => /line-code/},
73 73 :content => /Demande cr\?\?e avec succ\?s/
74 74 end
75 75 end
76 76 set_tmp_attachments_directory
77 77 end
78 78
79 79 def test_show_diff_latin_1
80 80 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
81 81 ['inline', 'sbs'].each do |dt|
82 82 # 060719210727_changeset_iso8859-1.diff
83 83 get :show, :id => 5, :type => dt
84 84 assert_response :success
85 85 assert_template 'diff'
86 86 assert_equal 'text/html', @response.content_type
87 87 assert_tag 'th',
88 88 :attributes => {:class => "filename"},
89 89 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
90 90 assert_tag 'td',
91 91 :attributes => {:class => /line-code/},
92 92 :content => /Demande créée avec succès/
93 93 end
94 94 end
95 95 set_tmp_attachments_directory
96 96 end
97 97
98 98 def test_save_diff_type
99 99 @request.session[:user_id] = 1 # admin
100 100 user = User.find(1)
101 101 get :show, :id => 5
102 102 assert_response :success
103 103 assert_template 'diff'
104 104 user.reload
105 105 assert_equal "inline", user.pref[:diff_type]
106 106 get :show, :id => 5, :type => 'sbs'
107 107 assert_response :success
108 108 assert_template 'diff'
109 109 user.reload
110 110 assert_equal "sbs", user.pref[:diff_type]
111 111 end
112 112
113 113 def test_show_text_file
114 114 get :show, :id => 4
115 115 assert_response :success
116 116 assert_template 'file'
117 117 assert_equal 'text/html', @response.content_type
118 118 set_tmp_attachments_directory
119 119 end
120 120
121 121 def test_show_text_file_utf_8
122 122 set_tmp_attachments_directory
123 123 a = Attachment.new(:container => Issue.find(1),
124 124 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
125 125 :author => User.find(1))
126 126 assert a.save
127 127 assert_equal 'japanese-utf-8.txt', a.filename
128 128
129 129 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
130 130 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
131 131
132 132 get :show, :id => a.id
133 133 assert_response :success
134 134 assert_template 'file'
135 135 assert_equal 'text/html', @response.content_type
136 136 assert_tag :tag => 'th',
137 137 :content => '1',
138 138 :attributes => { :class => 'line-num' },
139 139 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
140 140 end
141 141
142 142 def test_show_text_file_replcace_cannot_convert_content
143 143 set_tmp_attachments_directory
144 144 with_settings :repositories_encodings => 'UTF-8' do
145 145 a = Attachment.new(:container => Issue.find(1),
146 146 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
147 147 :author => User.find(1))
148 148 assert a.save
149 149 assert_equal 'iso8859-1.txt', a.filename
150 150
151 151 get :show, :id => a.id
152 152 assert_response :success
153 153 assert_template 'file'
154 154 assert_equal 'text/html', @response.content_type
155 155 assert_tag :tag => 'th',
156 156 :content => '7',
157 157 :attributes => { :class => 'line-num' },
158 158 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
159 159 end
160 160 end
161 161
162 162 def test_show_text_file_latin_1
163 163 set_tmp_attachments_directory
164 164 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
165 165 a = Attachment.new(:container => Issue.find(1),
166 166 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
167 167 :author => User.find(1))
168 168 assert a.save
169 169 assert_equal 'iso8859-1.txt', a.filename
170 170
171 171 get :show, :id => a.id
172 172 assert_response :success
173 173 assert_template 'file'
174 174 assert_equal 'text/html', @response.content_type
175 175 assert_tag :tag => 'th',
176 176 :content => '7',
177 177 :attributes => { :class => 'line-num' },
178 178 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
179 179 end
180 180 end
181 181
182 182 def test_show_text_file_should_send_if_too_big
183 183 Setting.file_max_size_displayed = 512
184 184 Attachment.find(4).update_attribute :filesize, 754.kilobyte
185 185
186 186 get :show, :id => 4
187 187 assert_response :success
188 188 assert_equal 'application/x-ruby', @response.content_type
189 189 set_tmp_attachments_directory
190 190 end
191 191
192 192 def test_show_other
193 193 get :show, :id => 6
194 194 assert_response :success
195 195 assert_equal 'application/octet-stream', @response.content_type
196 196 set_tmp_attachments_directory
197 197 end
198 198
199 199 def test_show_file_from_private_issue_without_permission
200 200 get :show, :id => 15
201 201 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
202 202 set_tmp_attachments_directory
203 203 end
204 204
205 205 def test_show_file_from_private_issue_with_permission
206 206 @request.session[:user_id] = 2
207 207 get :show, :id => 15
208 208 assert_response :success
209 209 assert_tag 'h2', :content => /private.diff/
210 210 set_tmp_attachments_directory
211 211 end
212 212
213 213 def test_show_file_without_container_should_be_denied
214 214 set_tmp_attachments_directory
215 215 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
216 216
217 217 @request.session[:user_id] = 2
218 218 get :show, :id => attachment.id
219 219 assert_response 403
220 220 end
221 221
222 def test_show_invalid_should_respond_with_404
223 get :show, :id => 999
224 assert_response 404
225 end
226
222 227 def test_download_text_file
223 228 get :download, :id => 4
224 229 assert_response :success
225 230 assert_equal 'application/x-ruby', @response.content_type
226 231 set_tmp_attachments_directory
227 232 end
228 233
229 234 def test_download_version_file_with_issue_tracking_disabled
230 235 Project.find(1).disable_module! :issue_tracking
231 236 get :download, :id => 9
232 237 assert_response :success
233 238 end
234 239
235 240 def test_download_should_assign_content_type_if_blank
236 241 Attachment.find(4).update_attribute(:content_type, '')
237 242
238 243 get :download, :id => 4
239 244 assert_response :success
240 245 assert_equal 'text/x-ruby', @response.content_type
241 246 set_tmp_attachments_directory
242 247 end
243 248
244 249 def test_download_missing_file
245 250 get :download, :id => 2
246 251 assert_response 404
247 252 set_tmp_attachments_directory
248 253 end
249 254
250 255 def test_anonymous_on_private_private
251 256 get :download, :id => 7
252 257 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
253 258 set_tmp_attachments_directory
254 259 end
255 260
256 261 def test_destroy_issue_attachment
257 262 set_tmp_attachments_directory
258 263 issue = Issue.find(3)
259 264 @request.session[:user_id] = 2
260 265
261 266 assert_difference 'issue.attachments.count', -1 do
262 267 delete :destroy, :id => 1
263 268 end
264 269 # no referrer
265 270 assert_redirected_to '/projects/ecookbook'
266 271 assert_nil Attachment.find_by_id(1)
267 272 j = issue.journals.find(:first, :order => 'created_on DESC')
268 273 assert_equal 'attachment', j.details.first.property
269 274 assert_equal '1', j.details.first.prop_key
270 275 assert_equal 'error281.txt', j.details.first.old_value
271 276 end
272 277
273 278 def test_destroy_wiki_page_attachment
274 279 set_tmp_attachments_directory
275 280 @request.session[:user_id] = 2
276 281 assert_difference 'Attachment.count', -1 do
277 282 delete :destroy, :id => 3
278 283 assert_response 302
279 284 end
280 285 end
281 286
282 287 def test_destroy_project_attachment
283 288 set_tmp_attachments_directory
284 289 @request.session[:user_id] = 2
285 290 assert_difference 'Attachment.count', -1 do
286 291 delete :destroy, :id => 8
287 292 assert_response 302
288 293 end
289 294 end
290 295
291 296 def test_destroy_version_attachment
292 297 set_tmp_attachments_directory
293 298 @request.session[:user_id] = 2
294 299 assert_difference 'Attachment.count', -1 do
295 300 delete :destroy, :id => 9
296 301 assert_response 302
297 302 end
298 303 end
299 304
300 305 def test_destroy_without_permission
301 306 set_tmp_attachments_directory
302 307 assert_no_difference 'Attachment.count' do
303 308 delete :destroy, :id => 3
304 309 end
305 310 assert_response 302
306 311 assert Attachment.find_by_id(3)
307 312 end
308 313 end
@@ -1,116 +1,140
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'issue_categories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class IssueCategoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class IssueCategoriesControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories
26 26
27 27 def setup
28 28 @controller = IssueCategoriesController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 @request.session[:user_id] = 2
33 33 end
34 34
35 35 def test_new
36 36 @request.session[:user_id] = 2 # manager
37 37 get :new, :project_id => '1'
38 38 assert_response :success
39 39 assert_template 'new'
40 40 end
41 41
42 42 def test_create
43 43 @request.session[:user_id] = 2 # manager
44 44 assert_difference 'IssueCategory.count' do
45 45 post :create, :project_id => '1', :issue_category => {:name => 'New category'}
46 46 end
47 47 assert_redirected_to '/projects/ecookbook/settings/categories'
48 48 category = IssueCategory.find_by_name('New category')
49 49 assert_not_nil category
50 50 assert_equal 1, category.project_id
51 51 end
52 52
53 53 def test_create_failure
54 54 @request.session[:user_id] = 2
55 55 post :create, :project_id => '1', :issue_category => {:name => ''}
56 56 assert_response :success
57 57 assert_template 'new'
58 58 end
59 59
60 def test_create_from_issue_form
61 @request.session[:user_id] = 2 # manager
62 assert_difference 'IssueCategory.count' do
63 xhr :post, :create, :project_id => '1', :issue_category => {:name => 'New category'}
64 end
65 category = IssueCategory.first(:order => 'id DESC')
66 assert_equal 'New category', category.name
67
68 assert_response :success
69 assert_select_rjs :replace, 'issue_category_id' do
70 assert_select "option[value=#{category.id}][selected=selected]"
71 end
72 end
73
74 def test_create_from_issue_form_with_failure
75 @request.session[:user_id] = 2 # manager
76 assert_no_difference 'IssueCategory.count' do
77 xhr :post, :create, :project_id => '1', :issue_category => {:name => ''}
78 end
79
80 assert_response :success
81 assert_match /alert/, @response.body
82 end
83
60 84 def test_edit
61 85 @request.session[:user_id] = 2
62 86 get :edit, :id => 2
63 87 assert_response :success
64 88 assert_template 'edit'
65 89 end
66 90
67 91 def test_update
68 92 assert_no_difference 'IssueCategory.count' do
69 93 put :update, :id => 2, :issue_category => { :name => 'Testing' }
70 94 end
71 95 assert_redirected_to '/projects/ecookbook/settings/categories'
72 96 assert_equal 'Testing', IssueCategory.find(2).name
73 97 end
74 98
75 99 def test_update_failure
76 100 put :update, :id => 2, :issue_category => { :name => '' }
77 101 assert_response :success
78 102 assert_template 'edit'
79 103 end
80 104
81 105 def test_update_not_found
82 106 put :update, :id => 97, :issue_category => { :name => 'Testing' }
83 107 assert_response 404
84 108 end
85 109
86 110 def test_destroy_category_not_in_use
87 111 delete :destroy, :id => 2
88 112 assert_redirected_to '/projects/ecookbook/settings/categories'
89 113 assert_nil IssueCategory.find_by_id(2)
90 114 end
91 115
92 116 def test_destroy_category_in_use
93 117 delete :destroy, :id => 1
94 118 assert_response :success
95 119 assert_template 'destroy'
96 120 assert_not_nil IssueCategory.find_by_id(1)
97 121 end
98 122
99 123 def test_destroy_category_in_use_with_reassignment
100 124 issue = Issue.find(:first, :conditions => {:category_id => 1})
101 125 delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
102 126 assert_redirected_to '/projects/ecookbook/settings/categories'
103 127 assert_nil IssueCategory.find_by_id(1)
104 128 # check that the issue was reassign
105 129 assert_equal 2, issue.reload.category_id
106 130 end
107 131
108 132 def test_destroy_category_in_use_without_reassignment
109 133 issue = Issue.find(:first, :conditions => {:category_id => 1})
110 134 delete :destroy, :id => 1, :todo => 'nullify'
111 135 assert_redirected_to '/projects/ecookbook/settings/categories'
112 136 assert_nil IssueCategory.find_by_id(1)
113 137 # check that the issue category was nullified
114 138 assert_nil issue.reload.category_id
115 139 end
116 140 end
@@ -1,100 +1,114
1 1 require File.expand_path('../../test_helper', __FILE__)
2 2 require 'issue_statuses_controller'
3 3
4 4 # Re-raise errors caught by the controller.
5 5 class IssueStatusesController; def rescue_action(e) raise e end; end
6 6
7 7
8 8 class IssueStatusesControllerTest < ActionController::TestCase
9 9 fixtures :issue_statuses, :issues
10 10
11 11 def setup
12 12 @controller = IssueStatusesController.new
13 13 @request = ActionController::TestRequest.new
14 14 @response = ActionController::TestResponse.new
15 15 User.current = nil
16 16 @request.session[:user_id] = 1 # admin
17 17 end
18 18
19 19 def test_index
20 20 get :index
21 21 assert_response :success
22 22 assert_template 'index'
23 23 end
24 24
25 25 def test_index_by_anonymous_should_redirect_to_login_form
26 26 @request.session[:user_id] = nil
27 27 get :index
28 28 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fissue_statuses'
29 29 end
30 30
31 31 def test_index_by_user_should_respond_with_406
32 32 @request.session[:user_id] = 2
33 33 get :index
34 34 assert_response 406
35 35 end
36 36
37 37 def test_new
38 38 get :new
39 39 assert_response :success
40 40 assert_template 'new'
41 41 end
42 42
43 43 def test_create
44 44 assert_difference 'IssueStatus.count' do
45 45 post :create, :issue_status => {:name => 'New status'}
46 46 end
47 47 assert_redirected_to :action => 'index'
48 48 status = IssueStatus.find(:first, :order => 'id DESC')
49 49 assert_equal 'New status', status.name
50 50 end
51 51
52 def test_create_with_failure
53 post :create, :issue_status => {:name => ''}
54 assert_response :success
55 assert_template 'new'
56 assert_error_tag :content => /name can't be blank/i
57 end
58
52 59 def test_edit
53 60 get :edit, :id => '3'
54 61 assert_response :success
55 62 assert_template 'edit'
56 63 end
57 64
58 65 def test_update
59 66 put :update, :id => '3', :issue_status => {:name => 'Renamed status'}
60 67 assert_redirected_to :action => 'index'
61 68 status = IssueStatus.find(3)
62 69 assert_equal 'Renamed status', status.name
63 70 end
64 71
72 def test_update_with_failure
73 put :update, :id => '3', :issue_status => {:name => ''}
74 assert_response :success
75 assert_template 'edit'
76 assert_error_tag :content => /name can't be blank/i
77 end
78
65 79 def test_destroy
66 80 Issue.delete_all("status_id = 1")
67 81
68 82 assert_difference 'IssueStatus.count', -1 do
69 83 delete :destroy, :id => '1'
70 84 end
71 85 assert_redirected_to :action => 'index'
72 86 assert_nil IssueStatus.find_by_id(1)
73 87 end
74 88
75 89 def test_destroy_should_block_if_status_in_use
76 90 assert_not_nil Issue.find_by_status_id(1)
77 91
78 92 assert_no_difference 'IssueStatus.count' do
79 93 delete :destroy, :id => '1'
80 94 end
81 95 assert_redirected_to :action => 'index'
82 96 assert_not_nil IssueStatus.find_by_id(1)
83 97 end
84 98
85 99 def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_field
86 100 with_settings :issue_done_ratio => 'issue_field' do
87 101 post :update_issue_done_ratio
88 102 assert_match /not updated/, flash[:error].to_s
89 103 assert_redirected_to '/issue_statuses'
90 104 end
91 105 end
92 106
93 107 def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_status
94 108 with_settings :issue_done_ratio => 'issue_status' do
95 109 post :update_issue_done_ratio
96 110 assert_match /Issue done ratios updated/, flash[:notice].to_s
97 111 assert_redirected_to '/issue_statuses'
98 112 end
99 113 end
100 114 end
General Comments 0
You need to be logged in to leave comments. Login now