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