##// END OF EJS Templates
Merged r10501 from trunk...
Toshi MARUYAMA -
r10295:d69cae859f92
parent child
Show More
@@ -1,316 +1,321
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 @request.session[:user_id] = 1 # admin
99 user1 = User.find(1)
100 user1.pref[:diff_type] = nil
101 user1.preference.save
100 102 user = User.find(1)
103 assert_nil user.pref[:diff_type]
104
105 @request.session[:user_id] = 1 # admin
101 106 get :show, :id => 5
102 107 assert_response :success
103 108 assert_template 'diff'
104 109 user.reload
105 110 assert_equal "inline", user.pref[:diff_type]
106 111 get :show, :id => 5, :type => 'sbs'
107 112 assert_response :success
108 113 assert_template 'diff'
109 114 user.reload
110 115 assert_equal "sbs", user.pref[:diff_type]
111 116 end
112 117
113 118 def test_show_text_file
114 119 get :show, :id => 4
115 120 assert_response :success
116 121 assert_template 'file'
117 122 assert_equal 'text/html', @response.content_type
118 123 set_tmp_attachments_directory
119 124 end
120 125
121 126 def test_show_text_file_utf_8
122 127 set_tmp_attachments_directory
123 128 a = Attachment.new(:container => Issue.find(1),
124 129 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
125 130 :author => User.find(1))
126 131 assert a.save
127 132 assert_equal 'japanese-utf-8.txt', a.filename
128 133
129 134 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
130 135 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
131 136
132 137 get :show, :id => a.id
133 138 assert_response :success
134 139 assert_template 'file'
135 140 assert_equal 'text/html', @response.content_type
136 141 assert_tag :tag => 'th',
137 142 :content => '1',
138 143 :attributes => { :class => 'line-num' },
139 144 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
140 145 end
141 146
142 147 def test_show_text_file_replcace_cannot_convert_content
143 148 set_tmp_attachments_directory
144 149 with_settings :repositories_encodings => 'UTF-8' do
145 150 a = Attachment.new(:container => Issue.find(1),
146 151 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
147 152 :author => User.find(1))
148 153 assert a.save
149 154 assert_equal 'iso8859-1.txt', a.filename
150 155
151 156 get :show, :id => a.id
152 157 assert_response :success
153 158 assert_template 'file'
154 159 assert_equal 'text/html', @response.content_type
155 160 assert_tag :tag => 'th',
156 161 :content => '7',
157 162 :attributes => { :class => 'line-num' },
158 163 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
159 164 end
160 165 end
161 166
162 167 def test_show_text_file_latin_1
163 168 set_tmp_attachments_directory
164 169 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
165 170 a = Attachment.new(:container => Issue.find(1),
166 171 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
167 172 :author => User.find(1))
168 173 assert a.save
169 174 assert_equal 'iso8859-1.txt', a.filename
170 175
171 176 get :show, :id => a.id
172 177 assert_response :success
173 178 assert_template 'file'
174 179 assert_equal 'text/html', @response.content_type
175 180 assert_tag :tag => 'th',
176 181 :content => '7',
177 182 :attributes => { :class => 'line-num' },
178 183 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
179 184 end
180 185 end
181 186
182 187 def test_show_text_file_should_send_if_too_big
183 188 Setting.file_max_size_displayed = 512
184 189 Attachment.find(4).update_attribute :filesize, 754.kilobyte
185 190
186 191 get :show, :id => 4
187 192 assert_response :success
188 193 assert_equal 'application/x-ruby', @response.content_type
189 194 set_tmp_attachments_directory
190 195 end
191 196
192 197 def test_show_other
193 198 get :show, :id => 6
194 199 assert_response :success
195 200 assert_equal 'application/octet-stream', @response.content_type
196 201 set_tmp_attachments_directory
197 202 end
198 203
199 204 def test_show_file_from_private_issue_without_permission
200 205 get :show, :id => 15
201 206 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
202 207 set_tmp_attachments_directory
203 208 end
204 209
205 210 def test_show_file_from_private_issue_with_permission
206 211 @request.session[:user_id] = 2
207 212 get :show, :id => 15
208 213 assert_response :success
209 214 assert_tag 'h2', :content => /private.diff/
210 215 set_tmp_attachments_directory
211 216 end
212 217
213 218 def test_show_file_without_container_should_be_denied
214 219 set_tmp_attachments_directory
215 220 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
216 221
217 222 @request.session[:user_id] = 2
218 223 get :show, :id => attachment.id
219 224 assert_response 403
220 225 end
221 226
222 227 def test_show_invalid_should_respond_with_404
223 228 get :show, :id => 999
224 229 assert_response 404
225 230 end
226 231
227 232 def test_download_text_file
228 233 get :download, :id => 4
229 234 assert_response :success
230 235 assert_equal 'application/x-ruby', @response.content_type
231 236 set_tmp_attachments_directory
232 237 end
233 238
234 239 def test_download_version_file_with_issue_tracking_disabled
235 240 Project.find(1).disable_module! :issue_tracking
236 241 get :download, :id => 9
237 242 assert_response :success
238 243 end
239 244
240 245 def test_download_should_assign_content_type_if_blank
241 246 Attachment.find(4).update_attribute(:content_type, '')
242 247
243 248 get :download, :id => 4
244 249 assert_response :success
245 250 assert_equal 'text/x-ruby', @response.content_type
246 251 set_tmp_attachments_directory
247 252 end
248 253
249 254 def test_download_missing_file
250 255 get :download, :id => 2
251 256 assert_response 404
252 257 set_tmp_attachments_directory
253 258 end
254 259
255 260 def test_anonymous_on_private_private
256 261 get :download, :id => 7
257 262 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
258 263 set_tmp_attachments_directory
259 264 end
260 265
261 266 def test_destroy_issue_attachment
262 267 set_tmp_attachments_directory
263 268 issue = Issue.find(3)
264 269 @request.session[:user_id] = 2
265 270
266 271 assert_difference 'issue.attachments.count', -1 do
267 272 assert_difference 'Journal.count' do
268 273 delete :destroy, :id => 1
269 274 assert_redirected_to '/projects/ecookbook'
270 275 end
271 276 end
272 277 assert_nil Attachment.find_by_id(1)
273 278 j = Journal.first(:order => 'id DESC')
274 279 assert_equal issue, j.journalized
275 280 assert_equal 'attachment', j.details.first.property
276 281 assert_equal '1', j.details.first.prop_key
277 282 assert_equal 'error281.txt', j.details.first.old_value
278 283 assert_equal User.find(2), j.user
279 284 end
280 285
281 286 def test_destroy_wiki_page_attachment
282 287 set_tmp_attachments_directory
283 288 @request.session[:user_id] = 2
284 289 assert_difference 'Attachment.count', -1 do
285 290 delete :destroy, :id => 3
286 291 assert_response 302
287 292 end
288 293 end
289 294
290 295 def test_destroy_project_attachment
291 296 set_tmp_attachments_directory
292 297 @request.session[:user_id] = 2
293 298 assert_difference 'Attachment.count', -1 do
294 299 delete :destroy, :id => 8
295 300 assert_response 302
296 301 end
297 302 end
298 303
299 304 def test_destroy_version_attachment
300 305 set_tmp_attachments_directory
301 306 @request.session[:user_id] = 2
302 307 assert_difference 'Attachment.count', -1 do
303 308 delete :destroy, :id => 9
304 309 assert_response 302
305 310 end
306 311 end
307 312
308 313 def test_destroy_without_permission
309 314 set_tmp_attachments_directory
310 315 assert_no_difference 'Attachment.count' do
311 316 delete :destroy, :id => 3
312 317 end
313 318 assert_response 302
314 319 assert Attachment.find_by_id(3)
315 320 end
316 321 end
@@ -1,575 +1,580
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
20 20 class RepositoriesGitControllerTest < ActionController::TestCase
21 21 tests RepositoriesController
22 22
23 23 fixtures :projects, :users, :roles, :members, :member_roles,
24 24 :repositories, :enabled_modules
25 25
26 26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
27 27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 28 PRJ_ID = 3
29 29 CHAR_1_HEX = "\xc3\x9c"
30 30 NUM_REV = 28
31 31
32 32 ## Git, Mercurial and CVS path encodings are binary.
33 33 ## Subversion supports URL encoding for path.
34 34 ## Redmine Mercurial adapter and extension use URL encoding.
35 35 ## Git accepts only binary path in command line parameter.
36 36 ## So, there is no way to use binary command line parameter in JRuby.
37 37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
38 38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
39 39
40 40 def setup
41 41 @ruby19_non_utf8_pass =
42 42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
43 43
44 44 User.current = nil
45 45 @project = Project.find(PRJ_ID)
46 46 @repository = Repository::Git.create(
47 47 :project => @project,
48 48 :url => REPOSITORY_PATH,
49 49 :path_encoding => 'ISO-8859-1'
50 50 )
51 51 assert @repository
52 52 @char_1 = CHAR_1_HEX.dup
53 53 if @char_1.respond_to?(:force_encoding)
54 54 @char_1.force_encoding('UTF-8')
55 55 end
56 56 end
57 57
58 58 def test_create_and_update
59 59 @request.session[:user_id] = 1
60 60 assert_difference 'Repository.count' do
61 61 post :create, :project_id => 'subproject1',
62 62 :repository_scm => 'Git',
63 63 :repository => {
64 64 :url => '/test',
65 65 :is_default => '0',
66 66 :identifier => 'test-create',
67 67 :extra_report_last_commit => '1',
68 68 }
69 69 end
70 70 assert_response 302
71 71 repository = Repository.first(:order => 'id DESC')
72 72 assert_kind_of Repository::Git, repository
73 73 assert_equal '/test', repository.url
74 74 assert_equal true, repository.extra_report_last_commit
75 75
76 76 put :update, :id => repository.id,
77 77 :repository => {
78 78 :extra_report_last_commit => '0',
79 79 :identifier => 'test-update',
80 80 }
81 81 assert_response 302
82 82 repo2 = Repository.find(repository.id)
83 83 assert_equal 'test-update', repo2.identifier
84 84 assert_equal false, repo2.extra_report_last_commit
85 85 end
86 86
87 87 if File.directory?(REPOSITORY_PATH)
88 88 ## Ruby uses ANSI api to fork a process on Windows.
89 89 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
90 90 ## and these are incompatible with ASCII.
91 91 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
92 92 ## http://code.google.com/p/msysgit/issues/detail?id=80
93 93 ## So, Latin-1 path tests fail on Japanese Windows
94 94 WINDOWS_PASS = (Redmine::Platform.mswin? &&
95 95 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
96 96 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
97 97
98 98 def test_get_new
99 99 @request.session[:user_id] = 1
100 100 @project.repository.destroy
101 101 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
102 102 assert_response :success
103 103 assert_template 'new'
104 104 assert_kind_of Repository::Git, assigns(:repository)
105 105 assert assigns(:repository).new_record?
106 106 end
107 107
108 108 def test_browse_root
109 109 assert_equal 0, @repository.changesets.count
110 110 @repository.fetch_changesets
111 111 @project.reload
112 112 assert_equal NUM_REV, @repository.changesets.count
113 113
114 114 get :show, :id => PRJ_ID
115 115 assert_response :success
116 116 assert_template 'show'
117 117 assert_not_nil assigns(:entries)
118 118 assert_equal 9, assigns(:entries).size
119 119 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
120 120 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
121 121 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
122 122 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
123 123 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
124 124 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
125 125 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
126 126 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
127 127 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
128 128 assert_not_nil assigns(:changesets)
129 129 assert assigns(:changesets).size > 0
130 130 end
131 131
132 132 def test_browse_branch
133 133 assert_equal 0, @repository.changesets.count
134 134 @repository.fetch_changesets
135 135 @project.reload
136 136 assert_equal NUM_REV, @repository.changesets.count
137 137 get :show, :id => PRJ_ID, :rev => 'test_branch'
138 138 assert_response :success
139 139 assert_template 'show'
140 140 assert_not_nil assigns(:entries)
141 141 assert_equal 4, assigns(:entries).size
142 142 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
143 143 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
144 144 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
145 145 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
146 146 assert_not_nil assigns(:changesets)
147 147 assert assigns(:changesets).size > 0
148 148 end
149 149
150 150 def test_browse_tag
151 151 assert_equal 0, @repository.changesets.count
152 152 @repository.fetch_changesets
153 153 @project.reload
154 154 assert_equal NUM_REV, @repository.changesets.count
155 155 [
156 156 "tag00.lightweight",
157 157 "tag01.annotated",
158 158 ].each do |t1|
159 159 get :show, :id => PRJ_ID, :rev => t1
160 160 assert_response :success
161 161 assert_template 'show'
162 162 assert_not_nil assigns(:entries)
163 163 assert assigns(:entries).size > 0
164 164 assert_not_nil assigns(:changesets)
165 165 assert assigns(:changesets).size > 0
166 166 end
167 167 end
168 168
169 169 def test_browse_directory
170 170 assert_equal 0, @repository.changesets.count
171 171 @repository.fetch_changesets
172 172 @project.reload
173 173 assert_equal NUM_REV, @repository.changesets.count
174 174 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
175 175 assert_response :success
176 176 assert_template 'show'
177 177 assert_not_nil assigns(:entries)
178 178 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
179 179 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
180 180 assert_not_nil entry
181 181 assert_equal 'file', entry.kind
182 182 assert_equal 'images/edit.png', entry.path
183 183 assert_not_nil assigns(:changesets)
184 184 assert assigns(:changesets).size > 0
185 185 end
186 186
187 187 def test_browse_at_given_revision
188 188 assert_equal 0, @repository.changesets.count
189 189 @repository.fetch_changesets
190 190 @project.reload
191 191 assert_equal NUM_REV, @repository.changesets.count
192 192 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
193 193 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
194 194 assert_response :success
195 195 assert_template 'show'
196 196 assert_not_nil assigns(:entries)
197 197 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
198 198 assert_not_nil assigns(:changesets)
199 199 assert assigns(:changesets).size > 0
200 200 end
201 201
202 202 def test_changes
203 203 get :changes, :id => PRJ_ID,
204 204 :path => repository_path_hash(['images', 'edit.png'])[:param]
205 205 assert_response :success
206 206 assert_template 'changes'
207 207 assert_tag :tag => 'h2', :content => 'edit.png'
208 208 end
209 209
210 210 def test_entry_show
211 211 get :entry, :id => PRJ_ID,
212 212 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
213 213 assert_response :success
214 214 assert_template 'entry'
215 215 # Line 19
216 216 assert_tag :tag => 'th',
217 217 :content => '11',
218 218 :attributes => { :class => 'line-num' },
219 219 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
220 220 end
221 221
222 222 def test_entry_show_latin_1
223 223 if @ruby19_non_utf8_pass
224 224 puts_ruby19_non_utf8_pass()
225 225 elsif WINDOWS_PASS
226 226 puts WINDOWS_SKIP_STR
227 227 elsif JRUBY_SKIP
228 228 puts JRUBY_SKIP_STR
229 229 else
230 230 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
231 231 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
232 232 get :entry, :id => PRJ_ID,
233 233 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
234 234 :rev => r1
235 235 assert_response :success
236 236 assert_template 'entry'
237 237 assert_tag :tag => 'th',
238 238 :content => '1',
239 239 :attributes => { :class => 'line-num' },
240 240 :sibling => { :tag => 'td',
241 241 :content => /test-#{@char_1}.txt/ }
242 242 end
243 243 end
244 244 end
245 245 end
246 246
247 247 def test_entry_download
248 248 get :entry, :id => PRJ_ID,
249 249 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
250 250 :format => 'raw'
251 251 assert_response :success
252 252 # File content
253 253 assert @response.body.include?('WITHOUT ANY WARRANTY')
254 254 end
255 255
256 256 def test_directory_entry
257 257 get :entry, :id => PRJ_ID,
258 258 :path => repository_path_hash(['sources'])[:param]
259 259 assert_response :success
260 260 assert_template 'show'
261 261 assert_not_nil assigns(:entry)
262 262 assert_equal 'sources', assigns(:entry).name
263 263 end
264 264
265 265 def test_diff
266 266 assert_equal 0, @repository.changesets.count
267 267 @repository.fetch_changesets
268 268 @project.reload
269 269 assert_equal NUM_REV, @repository.changesets.count
270 270 # Full diff of changeset 2f9c0091
271 271 ['inline', 'sbs'].each do |dt|
272 272 get :diff,
273 273 :id => PRJ_ID,
274 274 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
275 275 :type => dt
276 276 assert_response :success
277 277 assert_template 'diff'
278 278 # Line 22 removed
279 279 assert_tag :tag => 'th',
280 280 :content => /22/,
281 281 :sibling => { :tag => 'td',
282 282 :attributes => { :class => /diff_out/ },
283 283 :content => /def remove/ }
284 284 assert_tag :tag => 'h2', :content => /2f9c0091/
285 285 end
286 286 end
287 287
288 288 def test_diff_with_rev_and_path
289 289 assert_equal 0, @repository.changesets.count
290 290 @repository.fetch_changesets
291 291 @project.reload
292 292 assert_equal NUM_REV, @repository.changesets.count
293 293 with_settings :diff_max_lines_displayed => 1000 do
294 294 # Full diff of changeset 2f9c0091
295 295 ['inline', 'sbs'].each do |dt|
296 296 get :diff,
297 297 :id => PRJ_ID,
298 298 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
299 299 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
300 300 :type => dt
301 301 assert_response :success
302 302 assert_template 'diff'
303 303 # Line 22 removed
304 304 assert_tag :tag => 'th',
305 305 :content => '22',
306 306 :sibling => { :tag => 'td',
307 307 :attributes => { :class => /diff_out/ },
308 308 :content => /def remove/ }
309 309 assert_tag :tag => 'h2', :content => /2f9c0091/
310 310 end
311 311 end
312 312 end
313 313
314 314 def test_diff_truncated
315 315 assert_equal 0, @repository.changesets.count
316 316 @repository.fetch_changesets
317 317 @project.reload
318 318 assert_equal NUM_REV, @repository.changesets.count
319 319
320 320 with_settings :diff_max_lines_displayed => 5 do
321 321 # Truncated diff of changeset 2f9c0091
322 322 with_cache do
323 323 with_settings :default_language => 'en' do
324 324 get :diff, :id => PRJ_ID, :type => 'inline',
325 325 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
326 326 assert_response :success
327 327 assert @response.body.include?("... This diff was truncated")
328 328 end
329 329 with_settings :default_language => 'fr' do
330 330 get :diff, :id => PRJ_ID, :type => 'inline',
331 331 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
332 332 assert_response :success
333 333 assert ! @response.body.include?("... This diff was truncated")
334 334 assert @response.body.include?("... Ce diff")
335 335 end
336 336 end
337 337 end
338 338 end
339 339
340 340 def test_diff_two_revs
341 341 assert_equal 0, @repository.changesets.count
342 342 @repository.fetch_changesets
343 343 @project.reload
344 344 assert_equal NUM_REV, @repository.changesets.count
345 345 ['inline', 'sbs'].each do |dt|
346 346 get :diff,
347 347 :id => PRJ_ID,
348 348 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
349 349 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
350 350 :type => dt
351 351 assert_response :success
352 352 assert_template 'diff'
353 353 diff = assigns(:diff)
354 354 assert_not_nil diff
355 355 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
356 356 end
357 357 end
358 358
359 359 def test_diff_latin_1
360 360 if @ruby19_non_utf8_pass
361 361 puts_ruby19_non_utf8_pass()
362 362 else
363 363 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
364 364 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
365 365 ['inline', 'sbs'].each do |dt|
366 366 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
367 367 assert_response :success
368 368 assert_template 'diff'
369 369 assert_tag :tag => 'thead',
370 370 :descendant => {
371 371 :tag => 'th',
372 372 :attributes => { :class => 'filename' } ,
373 373 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
374 374 },
375 375 :sibling => {
376 376 :tag => 'tbody',
377 377 :descendant => {
378 378 :tag => 'td',
379 379 :attributes => { :class => /diff_in/ },
380 380 :content => /test-#{@char_1}.txt/
381 381 }
382 382 }
383 383 end
384 384 end
385 385 end
386 386 end
387 387 end
388 388
389 389 def test_save_diff_type
390 @request.session[:user_id] = 1 # admin
390 user1 = User.find(1)
391 user1.pref[:diff_type] = nil
392 user1.preference.save
391 393 user = User.find(1)
394 assert_nil user.pref[:diff_type]
395
396 @request.session[:user_id] = 1 # admin
392 397 get :diff,
393 398 :id => PRJ_ID,
394 399 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
395 400 assert_response :success
396 401 assert_template 'diff'
397 402 user.reload
398 403 assert_equal "inline", user.pref[:diff_type]
399 404 get :diff,
400 405 :id => PRJ_ID,
401 406 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
402 407 :type => 'sbs'
403 408 assert_response :success
404 409 assert_template 'diff'
405 410 user.reload
406 411 assert_equal "sbs", user.pref[:diff_type]
407 412 end
408 413
409 414 def test_annotate
410 415 get :annotate, :id => PRJ_ID,
411 416 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
412 417 assert_response :success
413 418 assert_template 'annotate'
414 419 # Line 24, changeset 2f9c0091
415 420 assert_tag :tag => 'th', :content => '24',
416 421 :sibling => {
417 422 :tag => 'td',
418 423 :child => {
419 424 :tag => 'a',
420 425 :content => /2f9c0091/
421 426 }
422 427 }
423 428 assert_tag :tag => 'th', :content => '24',
424 429 :sibling => { :tag => 'td', :content => /jsmith/ }
425 430 assert_tag :tag => 'th', :content => '24',
426 431 :sibling => {
427 432 :tag => 'td',
428 433 :child => {
429 434 :tag => 'a',
430 435 :content => /2f9c0091/
431 436 }
432 437 }
433 438 assert_tag :tag => 'th', :content => '24',
434 439 :sibling => { :tag => 'td', :content => /watcher =/ }
435 440 end
436 441
437 442 def test_annotate_at_given_revision
438 443 assert_equal 0, @repository.changesets.count
439 444 @repository.fetch_changesets
440 445 @project.reload
441 446 assert_equal NUM_REV, @repository.changesets.count
442 447 get :annotate, :id => PRJ_ID, :rev => 'deff7',
443 448 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
444 449 assert_response :success
445 450 assert_template 'annotate'
446 451 assert_tag :tag => 'h2', :content => /@ deff712f/
447 452 end
448 453
449 454 def test_annotate_binary_file
450 455 get :annotate, :id => PRJ_ID,
451 456 :path => repository_path_hash(['images', 'edit.png'])[:param]
452 457 assert_response 500
453 458 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
454 459 :content => /cannot be annotated/
455 460 end
456 461
457 462 def test_annotate_error_when_too_big
458 463 with_settings :file_max_size_displayed => 1 do
459 464 get :annotate, :id => PRJ_ID,
460 465 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
461 466 :rev => 'deff712f'
462 467 assert_response 500
463 468 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
464 469 :content => /exceeds the maximum text file size/
465 470
466 471 get :annotate, :id => PRJ_ID,
467 472 :path => repository_path_hash(['README'])[:param],
468 473 :rev => '7234cb2'
469 474 assert_response :success
470 475 assert_template 'annotate'
471 476 end
472 477 end
473 478
474 479 def test_annotate_latin_1
475 480 if @ruby19_non_utf8_pass
476 481 puts_ruby19_non_utf8_pass()
477 482 elsif WINDOWS_PASS
478 483 puts WINDOWS_SKIP_STR
479 484 elsif JRUBY_SKIP
480 485 puts JRUBY_SKIP_STR
481 486 else
482 487 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
483 488 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
484 489 get :annotate, :id => PRJ_ID,
485 490 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
486 491 :rev => r1
487 492 assert_tag :tag => 'th',
488 493 :content => '1',
489 494 :attributes => { :class => 'line-num' },
490 495 :sibling => { :tag => 'td',
491 496 :content => /test-#{@char_1}.txt/ }
492 497 end
493 498 end
494 499 end
495 500 end
496 501
497 502 def test_revision
498 503 assert_equal 0, @repository.changesets.count
499 504 @repository.fetch_changesets
500 505 @project.reload
501 506 assert_equal NUM_REV, @repository.changesets.count
502 507 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
503 508 get :revision, :id => PRJ_ID, :rev => r
504 509 assert_response :success
505 510 assert_template 'revision'
506 511 end
507 512 end
508 513
509 514 def test_empty_revision
510 515 assert_equal 0, @repository.changesets.count
511 516 @repository.fetch_changesets
512 517 @project.reload
513 518 assert_equal NUM_REV, @repository.changesets.count
514 519 ['', ' ', nil].each do |r|
515 520 get :revision, :id => PRJ_ID, :rev => r
516 521 assert_response 404
517 522 assert_error_tag :content => /was not found/
518 523 end
519 524 end
520 525
521 526 def test_destroy_valid_repository
522 527 @request.session[:user_id] = 1 # admin
523 528 assert_equal 0, @repository.changesets.count
524 529 @repository.fetch_changesets
525 530 @project.reload
526 531 assert_equal NUM_REV, @repository.changesets.count
527 532
528 533 assert_difference 'Repository.count', -1 do
529 534 delete :destroy, :id => @repository.id
530 535 end
531 536 assert_response 302
532 537 @project.reload
533 538 assert_nil @project.repository
534 539 end
535 540
536 541 def test_destroy_invalid_repository
537 542 @request.session[:user_id] = 1 # admin
538 543 @project.repository.destroy
539 544 @repository = Repository::Git.create!(
540 545 :project => @project,
541 546 :url => "/invalid",
542 547 :path_encoding => 'ISO-8859-1'
543 548 )
544 549 @repository.fetch_changesets
545 550 @repository.reload
546 551 assert_equal 0, @repository.changesets.count
547 552
548 553 assert_difference 'Repository.count', -1 do
549 554 delete :destroy, :id => @repository.id
550 555 end
551 556 assert_response 302
552 557 @project.reload
553 558 assert_nil @project.repository
554 559 end
555 560
556 561 private
557 562
558 563 def puts_ruby19_non_utf8_pass
559 564 puts "TODO: This test fails in Ruby 1.9 " +
560 565 "and Encoding.default_external is not UTF-8. " +
561 566 "Current value is '#{Encoding.default_external.to_s}'"
562 567 end
563 568 else
564 569 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
565 570 def test_fake; assert true end
566 571 end
567 572
568 573 private
569 574 def with_cache(&block)
570 575 before = ActionController::Base.perform_caching
571 576 ActionController::Base.perform_caching = true
572 577 block.call
573 578 ActionController::Base.perform_caching = before
574 579 end
575 580 end
General Comments 0
You need to be logged in to leave comments. Login now