@@ -1,289 +1,274 | |||||
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 RepositoriesCvsControllerTest < ActionController::TestCase |
|
20 | class RepositoriesCvsControllerTest < 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/cvs_repository').to_s |
|
26 | REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s | |
27 | REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? |
|
27 | REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? | |
28 | # CVS module |
|
28 | # CVS module | |
29 | MODULE_NAME = 'test' |
|
29 | MODULE_NAME = 'test' | |
30 | PRJ_ID = 3 |
|
30 | PRJ_ID = 3 | |
31 | NUM_REV = 7 |
|
31 | NUM_REV = 7 | |
32 |
|
32 | |||
33 | def setup |
|
33 | def setup | |
34 | Setting.default_language = 'en' |
|
34 | Setting.default_language = 'en' | |
35 | User.current = nil |
|
35 | User.current = nil | |
36 |
|
36 | |||
37 | @project = Project.find(PRJ_ID) |
|
37 | @project = Project.find(PRJ_ID) | |
38 | @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID), |
|
38 | @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID), | |
39 | :root_url => REPOSITORY_PATH, |
|
39 | :root_url => REPOSITORY_PATH, | |
40 | :url => MODULE_NAME, |
|
40 | :url => MODULE_NAME, | |
41 | :log_encoding => 'UTF-8') |
|
41 | :log_encoding => 'UTF-8') | |
42 | assert @repository |
|
42 | assert @repository | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | if File.directory?(REPOSITORY_PATH) |
|
45 | if File.directory?(REPOSITORY_PATH) | |
46 | def test_get_new |
|
46 | def test_get_new | |
47 | @request.session[:user_id] = 1 |
|
47 | @request.session[:user_id] = 1 | |
48 | @project.repository.destroy |
|
48 | @project.repository.destroy | |
49 | get :new, :project_id => 'subproject1', :repository_scm => 'Cvs' |
|
49 | get :new, :project_id => 'subproject1', :repository_scm => 'Cvs' | |
50 | assert_response :success |
|
50 | assert_response :success | |
51 | assert_template 'new' |
|
51 | assert_template 'new' | |
52 | assert_kind_of Repository::Cvs, assigns(:repository) |
|
52 | assert_kind_of Repository::Cvs, assigns(:repository) | |
53 | assert assigns(:repository).new_record? |
|
53 | assert assigns(:repository).new_record? | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def test_browse_root |
|
56 | def test_browse_root | |
57 | assert_equal 0, @repository.changesets.count |
|
57 | assert_equal 0, @repository.changesets.count | |
58 | @repository.fetch_changesets |
|
58 | @repository.fetch_changesets | |
59 | @project.reload |
|
59 | @project.reload | |
60 | assert_equal NUM_REV, @repository.changesets.count |
|
60 | assert_equal NUM_REV, @repository.changesets.count | |
61 | get :show, :id => PRJ_ID |
|
61 | get :show, :id => PRJ_ID | |
62 | assert_response :success |
|
62 | assert_response :success | |
63 | assert_template 'show' |
|
63 | assert_template 'show' | |
64 | assert_not_nil assigns(:entries) |
|
64 | assert_not_nil assigns(:entries) | |
65 | assert_equal 3, assigns(:entries).size |
|
65 | assert_equal 3, assigns(:entries).size | |
66 |
|
66 | |||
67 | entry = assigns(:entries).detect {|e| e.name == 'images'} |
|
67 | entry = assigns(:entries).detect {|e| e.name == 'images'} | |
68 | assert_equal 'dir', entry.kind |
|
68 | assert_equal 'dir', entry.kind | |
69 |
|
69 | |||
70 | entry = assigns(:entries).detect {|e| e.name == 'README'} |
|
70 | entry = assigns(:entries).detect {|e| e.name == 'README'} | |
71 | assert_equal 'file', entry.kind |
|
71 | assert_equal 'file', entry.kind | |
72 |
|
72 | |||
73 | assert_not_nil assigns(:changesets) |
|
73 | assert_not_nil assigns(:changesets) | |
74 | assert assigns(:changesets).size > 0 |
|
74 | assert assigns(:changesets).size > 0 | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def test_browse_directory |
|
77 | def test_browse_directory | |
78 | assert_equal 0, @repository.changesets.count |
|
78 | assert_equal 0, @repository.changesets.count | |
79 | @repository.fetch_changesets |
|
79 | @repository.fetch_changesets | |
80 | @project.reload |
|
80 | @project.reload | |
81 | assert_equal NUM_REV, @repository.changesets.count |
|
81 | assert_equal NUM_REV, @repository.changesets.count | |
82 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param] |
|
82 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param] | |
83 | assert_response :success |
|
83 | assert_response :success | |
84 | assert_template 'show' |
|
84 | assert_template 'show' | |
85 | assert_not_nil assigns(:entries) |
|
85 | assert_not_nil assigns(:entries) | |
86 | assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
86 | assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
87 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
87 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
88 | assert_not_nil entry |
|
88 | assert_not_nil entry | |
89 | assert_equal 'file', entry.kind |
|
89 | assert_equal 'file', entry.kind | |
90 | assert_equal 'images/edit.png', entry.path |
|
90 | assert_equal 'images/edit.png', entry.path | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | def test_browse_at_given_revision |
|
93 | def test_browse_at_given_revision | |
94 | assert_equal 0, @repository.changesets.count |
|
94 | assert_equal 0, @repository.changesets.count | |
95 | @repository.fetch_changesets |
|
95 | @repository.fetch_changesets | |
96 | @project.reload |
|
96 | @project.reload | |
97 | assert_equal NUM_REV, @repository.changesets.count |
|
97 | assert_equal NUM_REV, @repository.changesets.count | |
98 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param], |
|
98 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param], | |
99 | :rev => 1 |
|
99 | :rev => 1 | |
100 | assert_response :success |
|
100 | assert_response :success | |
101 | assert_template 'show' |
|
101 | assert_template 'show' | |
102 | assert_not_nil assigns(:entries) |
|
102 | assert_not_nil assigns(:entries) | |
103 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
103 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | def test_entry |
|
106 | def test_entry | |
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 | get :entry, :id => PRJ_ID, |
|
111 | get :entry, :id => PRJ_ID, | |
112 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
112 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] | |
113 | assert_response :success |
|
113 | assert_response :success | |
114 | assert_template 'entry' |
|
114 | assert_template 'entry' | |
115 | assert_no_tag :tag => 'td', |
|
115 | assert_no_tag :tag => 'td', | |
116 | :attributes => { :class => /line-code/}, |
|
116 | :attributes => { :class => /line-code/}, | |
117 | :content => /before_filter/ |
|
117 | :content => /before_filter/ | |
118 | end |
|
118 | end | |
119 |
|
119 | |||
120 | def test_entry_at_given_revision |
|
120 | def test_entry_at_given_revision | |
121 | # changesets must be loaded |
|
121 | # changesets must be loaded | |
122 | assert_equal 0, @repository.changesets.count |
|
122 | assert_equal 0, @repository.changesets.count | |
123 | @repository.fetch_changesets |
|
123 | @repository.fetch_changesets | |
124 | @project.reload |
|
124 | @project.reload | |
125 | assert_equal NUM_REV, @repository.changesets.count |
|
125 | assert_equal NUM_REV, @repository.changesets.count | |
126 | get :entry, :id => PRJ_ID, |
|
126 | get :entry, :id => PRJ_ID, | |
127 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], |
|
127 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], | |
128 | :rev => 2 |
|
128 | :rev => 2 | |
129 | assert_response :success |
|
129 | assert_response :success | |
130 | assert_template 'entry' |
|
130 | assert_template 'entry' | |
131 | # this line was removed in r3 |
|
131 | # this line was removed in r3 | |
132 | assert_tag :tag => 'td', |
|
132 | assert_tag :tag => 'td', | |
133 | :attributes => { :class => /line-code/}, |
|
133 | :attributes => { :class => /line-code/}, | |
134 | :content => /before_filter/ |
|
134 | :content => /before_filter/ | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | def test_entry_not_found |
|
137 | def test_entry_not_found | |
138 | assert_equal 0, @repository.changesets.count |
|
138 | assert_equal 0, @repository.changesets.count | |
139 | @repository.fetch_changesets |
|
139 | @repository.fetch_changesets | |
140 | @project.reload |
|
140 | @project.reload | |
141 | assert_equal NUM_REV, @repository.changesets.count |
|
141 | assert_equal NUM_REV, @repository.changesets.count | |
142 | get :entry, :id => PRJ_ID, |
|
142 | get :entry, :id => PRJ_ID, | |
143 | :path => repository_path_hash(['sources', 'zzz.c'])[:param] |
|
143 | :path => repository_path_hash(['sources', 'zzz.c'])[:param] | |
144 | assert_tag :tag => 'p', |
|
144 | assert_tag :tag => 'p', | |
145 | :attributes => { :id => /errorExplanation/ }, |
|
145 | :attributes => { :id => /errorExplanation/ }, | |
146 | :content => /The entry or revision was not found in the repository/ |
|
146 | :content => /The entry or revision was not found in the repository/ | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | def test_entry_download |
|
149 | def test_entry_download | |
150 | assert_equal 0, @repository.changesets.count |
|
150 | assert_equal 0, @repository.changesets.count | |
151 | @repository.fetch_changesets |
|
151 | @repository.fetch_changesets | |
152 | @project.reload |
|
152 | @project.reload | |
153 | assert_equal NUM_REV, @repository.changesets.count |
|
153 | assert_equal NUM_REV, @repository.changesets.count | |
154 | get :entry, :id => PRJ_ID, |
|
154 | get :entry, :id => PRJ_ID, | |
155 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], |
|
155 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], | |
156 | :format => 'raw' |
|
156 | :format => 'raw' | |
157 | assert_response :success |
|
157 | assert_response :success | |
158 | end |
|
158 | end | |
159 |
|
159 | |||
160 | def test_directory_entry |
|
160 | def test_directory_entry | |
161 | assert_equal 0, @repository.changesets.count |
|
161 | assert_equal 0, @repository.changesets.count | |
162 | @repository.fetch_changesets |
|
162 | @repository.fetch_changesets | |
163 | @project.reload |
|
163 | @project.reload | |
164 | assert_equal NUM_REV, @repository.changesets.count |
|
164 | assert_equal NUM_REV, @repository.changesets.count | |
165 | get :entry, :id => PRJ_ID, |
|
165 | get :entry, :id => PRJ_ID, | |
166 | :path => repository_path_hash(['sources'])[:param] |
|
166 | :path => repository_path_hash(['sources'])[:param] | |
167 | assert_response :success |
|
167 | assert_response :success | |
168 | assert_template 'show' |
|
168 | assert_template 'show' | |
169 | assert_not_nil assigns(:entry) |
|
169 | assert_not_nil assigns(:entry) | |
170 | assert_equal 'sources', assigns(:entry).name |
|
170 | assert_equal 'sources', assigns(:entry).name | |
171 | end |
|
171 | end | |
172 |
|
172 | |||
173 | def test_diff |
|
173 | def test_diff | |
174 | assert_equal 0, @repository.changesets.count |
|
174 | assert_equal 0, @repository.changesets.count | |
175 | @repository.fetch_changesets |
|
175 | @repository.fetch_changesets | |
176 | @project.reload |
|
176 | @project.reload | |
177 | assert_equal NUM_REV, @repository.changesets.count |
|
177 | assert_equal NUM_REV, @repository.changesets.count | |
178 | ['inline', 'sbs'].each do |dt| |
|
178 | ['inline', 'sbs'].each do |dt| | |
179 | get :diff, :id => PRJ_ID, :rev => 3, :type => dt |
|
179 | get :diff, :id => PRJ_ID, :rev => 3, :type => dt | |
180 | assert_response :success |
|
180 | assert_response :success | |
181 | assert_template 'diff' |
|
181 | assert_template 'diff' | |
182 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' }, |
|
182 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' }, | |
183 | :content => /before_filter :require_login/ |
|
183 | :content => /before_filter :require_login/ | |
184 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, |
|
184 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, | |
185 | :content => /with one change/ |
|
185 | :content => /with one change/ | |
186 | end |
|
186 | end | |
187 | end |
|
187 | end | |
188 |
|
188 | |||
189 | def test_diff_new_files |
|
189 | def test_diff_new_files | |
190 | assert_equal 0, @repository.changesets.count |
|
190 | assert_equal 0, @repository.changesets.count | |
191 | @repository.fetch_changesets |
|
191 | @repository.fetch_changesets | |
192 | @project.reload |
|
192 | @project.reload | |
193 | assert_equal NUM_REV, @repository.changesets.count |
|
193 | assert_equal NUM_REV, @repository.changesets.count | |
194 | ['inline', 'sbs'].each do |dt| |
|
194 | ['inline', 'sbs'].each do |dt| | |
195 | get :diff, :id => PRJ_ID, :rev => 1, :type => dt |
|
195 | get :diff, :id => PRJ_ID, :rev => 1, :type => dt | |
196 | assert_response :success |
|
196 | assert_response :success | |
197 | assert_template 'diff' |
|
197 | assert_template 'diff' | |
198 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, |
|
198 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, | |
199 | :content => /watched.remove_watcher/ |
|
199 | :content => /watched.remove_watcher/ | |
200 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, |
|
200 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, | |
201 | :content => /test\/README/ |
|
201 | :content => /test\/README/ | |
202 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, |
|
202 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, | |
203 | :content => /test\/images\/delete.png / |
|
203 | :content => /test\/images\/delete.png / | |
204 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, |
|
204 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, | |
205 | :content => /test\/images\/edit.png/ |
|
205 | :content => /test\/images\/edit.png/ | |
206 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, |
|
206 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, | |
207 | :content => /test\/sources\/watchers_controller.rb/ |
|
207 | :content => /test\/sources\/watchers_controller.rb/ | |
208 | end |
|
208 | end | |
209 | end |
|
209 | end | |
210 |
|
210 | |||
211 | def test_annotate |
|
211 | def test_annotate | |
212 | assert_equal 0, @repository.changesets.count |
|
212 | assert_equal 0, @repository.changesets.count | |
213 | @repository.fetch_changesets |
|
213 | @repository.fetch_changesets | |
214 | @project.reload |
|
214 | @project.reload | |
215 | assert_equal NUM_REV, @repository.changesets.count |
|
215 | assert_equal NUM_REV, @repository.changesets.count | |
216 | get :annotate, :id => PRJ_ID, |
|
216 | get :annotate, :id => PRJ_ID, | |
217 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
217 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] | |
218 | assert_response :success |
|
218 | assert_response :success | |
219 | assert_template 'annotate' |
|
219 | assert_template 'annotate' | |
|
220 | ||||
220 | # 1.1 line |
|
221 | # 1.1 line | |
221 |
assert_t |
|
222 | assert_select 'tr' do | |
222 | :attributes => { :class => 'line-num' }, |
|
223 | assert_select 'th.line-num', :text => '21' | |
223 | :content => '21', |
|
224 | assert_select 'td.revision', :text => /1.1/ | |
224 | :sibling => { |
|
225 | assert_select 'td.author', :text => /LANG/ | |
225 | :tag => 'td', |
|
226 | end | |
226 | :attributes => { :class => 'revision' }, |
|
|||
227 | :content => /1.1/, |
|
|||
228 | :sibling => { |
|
|||
229 | :tag => 'td', |
|
|||
230 | :attributes => { :class => 'author' }, |
|
|||
231 | :content => /LANG/ |
|
|||
232 | } |
|
|||
233 | } |
|
|||
234 | # 1.2 line |
|
227 | # 1.2 line | |
235 |
assert_t |
|
228 | assert_select 'tr' do | |
236 | :attributes => { :class => 'line-num' }, |
|
229 | assert_select 'th.line-num', :text => '32' | |
237 | :content => '32', |
|
230 | assert_select 'td.revision', :text => /1.2/ | |
238 | :sibling => { |
|
231 | assert_select 'td.author', :text => /LANG/ | |
239 | :tag => 'td', |
|
232 | end | |
240 | :attributes => { :class => 'revision' }, |
|
|||
241 | :content => /1.2/, |
|
|||
242 | :sibling => { |
|
|||
243 | :tag => 'td', |
|
|||
244 | :attributes => { :class => 'author' }, |
|
|||
245 | :content => /LANG/ |
|
|||
246 | } |
|
|||
247 | } |
|
|||
248 | end |
|
233 | end | |
249 |
|
234 | |||
250 | def test_destroy_valid_repository |
|
235 | def test_destroy_valid_repository | |
251 | @request.session[:user_id] = 1 # admin |
|
236 | @request.session[:user_id] = 1 # admin | |
252 | assert_equal 0, @repository.changesets.count |
|
237 | assert_equal 0, @repository.changesets.count | |
253 | @repository.fetch_changesets |
|
238 | @repository.fetch_changesets | |
254 | @project.reload |
|
239 | @project.reload | |
255 | assert_equal NUM_REV, @repository.changesets.count |
|
240 | assert_equal NUM_REV, @repository.changesets.count | |
256 |
|
241 | |||
257 | assert_difference 'Repository.count', -1 do |
|
242 | assert_difference 'Repository.count', -1 do | |
258 | delete :destroy, :id => @repository.id |
|
243 | delete :destroy, :id => @repository.id | |
259 | end |
|
244 | end | |
260 | assert_response 302 |
|
245 | assert_response 302 | |
261 | @project.reload |
|
246 | @project.reload | |
262 | assert_nil @project.repository |
|
247 | assert_nil @project.repository | |
263 | end |
|
248 | end | |
264 |
|
249 | |||
265 | def test_destroy_invalid_repository |
|
250 | def test_destroy_invalid_repository | |
266 | @request.session[:user_id] = 1 # admin |
|
251 | @request.session[:user_id] = 1 # admin | |
267 | @project.repository.destroy |
|
252 | @project.repository.destroy | |
268 | @repository = Repository::Cvs.create!( |
|
253 | @repository = Repository::Cvs.create!( | |
269 | :project => Project.find(PRJ_ID), |
|
254 | :project => Project.find(PRJ_ID), | |
270 | :root_url => "/invalid", |
|
255 | :root_url => "/invalid", | |
271 | :url => MODULE_NAME, |
|
256 | :url => MODULE_NAME, | |
272 | :log_encoding => 'UTF-8' |
|
257 | :log_encoding => 'UTF-8' | |
273 | ) |
|
258 | ) | |
274 | @repository.fetch_changesets |
|
259 | @repository.fetch_changesets | |
275 | @project.reload |
|
260 | @project.reload | |
276 | assert_equal 0, @repository.changesets.count |
|
261 | assert_equal 0, @repository.changesets.count | |
277 |
|
262 | |||
278 | assert_difference 'Repository.count', -1 do |
|
263 | assert_difference 'Repository.count', -1 do | |
279 | delete :destroy, :id => @repository.id |
|
264 | delete :destroy, :id => @repository.id | |
280 | end |
|
265 | end | |
281 | assert_response 302 |
|
266 | assert_response 302 | |
282 | @project.reload |
|
267 | @project.reload | |
283 | assert_nil @project.repository |
|
268 | assert_nil @project.repository | |
284 | end |
|
269 | end | |
285 | else |
|
270 | else | |
286 | puts "CVS test repository NOT FOUND. Skipping functional tests !!!" |
|
271 | puts "CVS test repository NOT FOUND. Skipping functional tests !!!" | |
287 | def test_fake; assert true end |
|
272 | def test_fake; assert true end | |
288 | end |
|
273 | end | |
289 | end |
|
274 | end |
@@ -1,547 +1,534 | |||||
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 |
|
56 | |||
57 | Setting.default_language = 'en' |
|
57 | Setting.default_language = 'en' | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def test_create_and_update |
|
60 | def test_create_and_update | |
61 | @request.session[:user_id] = 1 |
|
61 | @request.session[:user_id] = 1 | |
62 | assert_difference 'Repository.count' do |
|
62 | assert_difference 'Repository.count' do | |
63 | post :create, :project_id => 'subproject1', |
|
63 | post :create, :project_id => 'subproject1', | |
64 | :repository_scm => 'Git', |
|
64 | :repository_scm => 'Git', | |
65 | :repository => { |
|
65 | :repository => { | |
66 | :url => '/test', |
|
66 | :url => '/test', | |
67 | :is_default => '0', |
|
67 | :is_default => '0', | |
68 | :identifier => 'test-create', |
|
68 | :identifier => 'test-create', | |
69 | :extra_report_last_commit => '1', |
|
69 | :extra_report_last_commit => '1', | |
70 | } |
|
70 | } | |
71 | end |
|
71 | end | |
72 | assert_response 302 |
|
72 | assert_response 302 | |
73 | repository = Repository.first(:order => 'id DESC') |
|
73 | repository = Repository.first(:order => 'id DESC') | |
74 | assert_kind_of Repository::Git, repository |
|
74 | assert_kind_of Repository::Git, repository | |
75 | assert_equal '/test', repository.url |
|
75 | assert_equal '/test', repository.url | |
76 | assert_equal true, repository.extra_report_last_commit |
|
76 | assert_equal true, repository.extra_report_last_commit | |
77 |
|
77 | |||
78 | put :update, :id => repository.id, |
|
78 | put :update, :id => repository.id, | |
79 | :repository => { |
|
79 | :repository => { | |
80 | :extra_report_last_commit => '0' |
|
80 | :extra_report_last_commit => '0' | |
81 | } |
|
81 | } | |
82 | assert_response 302 |
|
82 | assert_response 302 | |
83 | repo2 = Repository.find(repository.id) |
|
83 | repo2 = Repository.find(repository.id) | |
84 | assert_equal false, repo2.extra_report_last_commit |
|
84 | assert_equal false, repo2.extra_report_last_commit | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | if File.directory?(REPOSITORY_PATH) |
|
87 | if File.directory?(REPOSITORY_PATH) | |
88 | ## Ruby uses ANSI api to fork a process on Windows. |
|
88 | ## Ruby uses ANSI api to fork a process on Windows. | |
89 | ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem |
|
89 | ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem | |
90 | ## and these are incompatible with ASCII. |
|
90 | ## and these are incompatible with ASCII. | |
91 | ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10 |
|
91 | ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10 | |
92 | ## http://code.google.com/p/msysgit/issues/detail?id=80 |
|
92 | ## http://code.google.com/p/msysgit/issues/detail?id=80 | |
93 | ## So, Latin-1 path tests fail on Japanese Windows |
|
93 | ## So, Latin-1 path tests fail on Japanese Windows | |
94 | WINDOWS_PASS = (Redmine::Platform.mswin? && |
|
94 | WINDOWS_PASS = (Redmine::Platform.mswin? && | |
95 | Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10])) |
|
95 | Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10])) | |
96 | WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10" |
|
96 | WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10" | |
97 |
|
97 | |||
98 | def test_get_new |
|
98 | def test_get_new | |
99 | @request.session[:user_id] = 1 |
|
99 | @request.session[:user_id] = 1 | |
100 | @project.repository.destroy |
|
100 | @project.repository.destroy | |
101 | get :new, :project_id => 'subproject1', :repository_scm => 'Git' |
|
101 | get :new, :project_id => 'subproject1', :repository_scm => 'Git' | |
102 | assert_response :success |
|
102 | assert_response :success | |
103 | assert_template 'new' |
|
103 | assert_template 'new' | |
104 | assert_kind_of Repository::Git, assigns(:repository) |
|
104 | assert_kind_of Repository::Git, assigns(:repository) | |
105 | assert assigns(:repository).new_record? |
|
105 | assert assigns(:repository).new_record? | |
106 | end |
|
106 | end | |
107 |
|
107 | |||
108 | def test_browse_root |
|
108 | def test_browse_root | |
109 | assert_equal 0, @repository.changesets.count |
|
109 | assert_equal 0, @repository.changesets.count | |
110 | @repository.fetch_changesets |
|
110 | @repository.fetch_changesets | |
111 | @project.reload |
|
111 | @project.reload | |
112 | assert_equal NUM_REV, @repository.changesets.count |
|
112 | assert_equal NUM_REV, @repository.changesets.count | |
113 |
|
113 | |||
114 | get :show, :id => PRJ_ID |
|
114 | get :show, :id => PRJ_ID | |
115 | assert_response :success |
|
115 | assert_response :success | |
116 | assert_template 'show' |
|
116 | assert_template 'show' | |
117 | assert_not_nil assigns(:entries) |
|
117 | assert_not_nil assigns(:entries) | |
118 | assert_equal 9, assigns(:entries).size |
|
118 | assert_equal 9, assigns(:entries).size | |
119 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
119 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} | |
120 | assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'} |
|
120 | assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'} | |
121 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
121 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} | |
122 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
122 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} | |
123 | assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} |
|
123 | assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} | |
124 | assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} |
|
124 | assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} | |
125 | assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} |
|
125 | assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} | |
126 | assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'} |
|
126 | assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'} | |
127 | assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'} |
|
127 | assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'} | |
128 | assert_not_nil assigns(:changesets) |
|
128 | assert_not_nil assigns(:changesets) | |
129 | assert assigns(:changesets).size > 0 |
|
129 | assert assigns(:changesets).size > 0 | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
132 | def test_browse_branch |
|
132 | def test_browse_branch | |
133 | assert_equal 0, @repository.changesets.count |
|
133 | assert_equal 0, @repository.changesets.count | |
134 | @repository.fetch_changesets |
|
134 | @repository.fetch_changesets | |
135 | @project.reload |
|
135 | @project.reload | |
136 | assert_equal NUM_REV, @repository.changesets.count |
|
136 | assert_equal NUM_REV, @repository.changesets.count | |
137 | get :show, :id => PRJ_ID, :rev => 'test_branch' |
|
137 | get :show, :id => PRJ_ID, :rev => 'test_branch' | |
138 | assert_response :success |
|
138 | assert_response :success | |
139 | assert_template 'show' |
|
139 | assert_template 'show' | |
140 | assert_not_nil assigns(:entries) |
|
140 | assert_not_nil assigns(:entries) | |
141 | assert_equal 4, assigns(:entries).size |
|
141 | assert_equal 4, assigns(:entries).size | |
142 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
142 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} | |
143 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
143 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} | |
144 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
144 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} | |
145 | assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'} |
|
145 | assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'} | |
146 | assert_not_nil assigns(:changesets) |
|
146 | assert_not_nil assigns(:changesets) | |
147 | assert assigns(:changesets).size > 0 |
|
147 | assert assigns(:changesets).size > 0 | |
148 | end |
|
148 | end | |
149 |
|
149 | |||
150 | def test_browse_tag |
|
150 | def test_browse_tag | |
151 | assert_equal 0, @repository.changesets.count |
|
151 | assert_equal 0, @repository.changesets.count | |
152 | @repository.fetch_changesets |
|
152 | @repository.fetch_changesets | |
153 | @project.reload |
|
153 | @project.reload | |
154 | assert_equal NUM_REV, @repository.changesets.count |
|
154 | assert_equal NUM_REV, @repository.changesets.count | |
155 | [ |
|
155 | [ | |
156 | "tag00.lightweight", |
|
156 | "tag00.lightweight", | |
157 | "tag01.annotated", |
|
157 | "tag01.annotated", | |
158 | ].each do |t1| |
|
158 | ].each do |t1| | |
159 | get :show, :id => PRJ_ID, :rev => t1 |
|
159 | get :show, :id => PRJ_ID, :rev => t1 | |
160 | assert_response :success |
|
160 | assert_response :success | |
161 | assert_template 'show' |
|
161 | assert_template 'show' | |
162 | assert_not_nil assigns(:entries) |
|
162 | assert_not_nil assigns(:entries) | |
163 | assert assigns(:entries).size > 0 |
|
163 | assert assigns(:entries).size > 0 | |
164 | assert_not_nil assigns(:changesets) |
|
164 | assert_not_nil assigns(:changesets) | |
165 | assert assigns(:changesets).size > 0 |
|
165 | assert assigns(:changesets).size > 0 | |
166 | end |
|
166 | end | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | def test_browse_directory |
|
169 | def test_browse_directory | |
170 | assert_equal 0, @repository.changesets.count |
|
170 | assert_equal 0, @repository.changesets.count | |
171 | @repository.fetch_changesets |
|
171 | @repository.fetch_changesets | |
172 | @project.reload |
|
172 | @project.reload | |
173 | assert_equal NUM_REV, @repository.changesets.count |
|
173 | assert_equal NUM_REV, @repository.changesets.count | |
174 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param] |
|
174 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param] | |
175 | assert_response :success |
|
175 | assert_response :success | |
176 | assert_template 'show' |
|
176 | assert_template 'show' | |
177 | assert_not_nil assigns(:entries) |
|
177 | assert_not_nil assigns(:entries) | |
178 | assert_equal ['edit.png'], assigns(:entries).collect(&:name) |
|
178 | assert_equal ['edit.png'], assigns(:entries).collect(&:name) | |
179 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
179 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
180 | assert_not_nil entry |
|
180 | assert_not_nil entry | |
181 | assert_equal 'file', entry.kind |
|
181 | assert_equal 'file', entry.kind | |
182 | assert_equal 'images/edit.png', entry.path |
|
182 | assert_equal 'images/edit.png', entry.path | |
183 | assert_not_nil assigns(:changesets) |
|
183 | assert_not_nil assigns(:changesets) | |
184 | assert assigns(:changesets).size > 0 |
|
184 | assert assigns(:changesets).size > 0 | |
185 | end |
|
185 | end | |
186 |
|
186 | |||
187 | def test_browse_at_given_revision |
|
187 | def test_browse_at_given_revision | |
188 | assert_equal 0, @repository.changesets.count |
|
188 | assert_equal 0, @repository.changesets.count | |
189 | @repository.fetch_changesets |
|
189 | @repository.fetch_changesets | |
190 | @project.reload |
|
190 | @project.reload | |
191 | assert_equal NUM_REV, @repository.changesets.count |
|
191 | assert_equal NUM_REV, @repository.changesets.count | |
192 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param], |
|
192 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param], | |
193 | :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' |
|
193 | :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' | |
194 | assert_response :success |
|
194 | assert_response :success | |
195 | assert_template 'show' |
|
195 | assert_template 'show' | |
196 | assert_not_nil assigns(:entries) |
|
196 | assert_not_nil assigns(:entries) | |
197 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
197 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |
198 | assert_not_nil assigns(:changesets) |
|
198 | assert_not_nil assigns(:changesets) | |
199 | assert assigns(:changesets).size > 0 |
|
199 | assert assigns(:changesets).size > 0 | |
200 | end |
|
200 | end | |
201 |
|
201 | |||
202 | def test_changes |
|
202 | def test_changes | |
203 | get :changes, :id => PRJ_ID, |
|
203 | get :changes, :id => PRJ_ID, | |
204 | :path => repository_path_hash(['images', 'edit.png'])[:param] |
|
204 | :path => repository_path_hash(['images', 'edit.png'])[:param] | |
205 | assert_response :success |
|
205 | assert_response :success | |
206 | assert_template 'changes' |
|
206 | assert_template 'changes' | |
207 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
207 | assert_tag :tag => 'h2', :content => 'edit.png' | |
208 | end |
|
208 | end | |
209 |
|
209 | |||
210 | def test_entry_show |
|
210 | def test_entry_show | |
211 | get :entry, :id => PRJ_ID, |
|
211 | get :entry, :id => PRJ_ID, | |
212 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
212 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] | |
213 | assert_response :success |
|
213 | assert_response :success | |
214 | assert_template 'entry' |
|
214 | assert_template 'entry' | |
215 | # Line 19 |
|
215 | # Line 19 | |
216 | assert_tag :tag => 'th', |
|
216 | assert_tag :tag => 'th', | |
217 | :content => '11', |
|
217 | :content => '11', | |
218 | :attributes => { :class => 'line-num' }, |
|
218 | :attributes => { :class => 'line-num' }, | |
219 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
|
219 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } | |
220 | end |
|
220 | end | |
221 |
|
221 | |||
222 | def test_entry_show_latin_1 |
|
222 | def test_entry_show_latin_1 | |
223 | if @ruby19_non_utf8_pass |
|
223 | if @ruby19_non_utf8_pass | |
224 | puts_ruby19_non_utf8_pass() |
|
224 | puts_ruby19_non_utf8_pass() | |
225 | elsif WINDOWS_PASS |
|
225 | elsif WINDOWS_PASS | |
226 | puts WINDOWS_SKIP_STR |
|
226 | puts WINDOWS_SKIP_STR | |
227 | elsif JRUBY_SKIP |
|
227 | elsif JRUBY_SKIP | |
228 | puts JRUBY_SKIP_STR |
|
228 | puts JRUBY_SKIP_STR | |
229 | else |
|
229 | else | |
230 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
230 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
231 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| |
|
231 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| | |
232 | get :entry, :id => PRJ_ID, |
|
232 | get :entry, :id => PRJ_ID, | |
233 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], |
|
233 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], | |
234 | :rev => r1 |
|
234 | :rev => r1 | |
235 | assert_response :success |
|
235 | assert_response :success | |
236 | assert_template 'entry' |
|
236 | assert_template 'entry' | |
237 | assert_tag :tag => 'th', |
|
237 | assert_tag :tag => 'th', | |
238 | :content => '1', |
|
238 | :content => '1', | |
239 | :attributes => { :class => 'line-num' }, |
|
239 | :attributes => { :class => 'line-num' }, | |
240 | :sibling => { :tag => 'td', |
|
240 | :sibling => { :tag => 'td', | |
241 | :content => /test-#{@char_1}.txt/ } |
|
241 | :content => /test-#{@char_1}.txt/ } | |
242 | end |
|
242 | end | |
243 | end |
|
243 | end | |
244 | end |
|
244 | end | |
245 | end |
|
245 | end | |
246 |
|
246 | |||
247 | def test_entry_download |
|
247 | def test_entry_download | |
248 | get :entry, :id => PRJ_ID, |
|
248 | get :entry, :id => PRJ_ID, | |
249 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], |
|
249 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], | |
250 | :format => 'raw' |
|
250 | :format => 'raw' | |
251 | assert_response :success |
|
251 | assert_response :success | |
252 | # File content |
|
252 | # File content | |
253 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
|
253 | assert @response.body.include?('WITHOUT ANY WARRANTY') | |
254 | end |
|
254 | end | |
255 |
|
255 | |||
256 | def test_directory_entry |
|
256 | def test_directory_entry | |
257 | get :entry, :id => PRJ_ID, |
|
257 | get :entry, :id => PRJ_ID, | |
258 | :path => repository_path_hash(['sources'])[:param] |
|
258 | :path => repository_path_hash(['sources'])[:param] | |
259 | assert_response :success |
|
259 | assert_response :success | |
260 | assert_template 'show' |
|
260 | assert_template 'show' | |
261 | assert_not_nil assigns(:entry) |
|
261 | assert_not_nil assigns(:entry) | |
262 | assert_equal 'sources', assigns(:entry).name |
|
262 | assert_equal 'sources', assigns(:entry).name | |
263 | end |
|
263 | end | |
264 |
|
264 | |||
265 | def test_diff |
|
265 | def test_diff | |
266 | assert_equal 0, @repository.changesets.count |
|
266 | assert_equal 0, @repository.changesets.count | |
267 | @repository.fetch_changesets |
|
267 | @repository.fetch_changesets | |
268 | @project.reload |
|
268 | @project.reload | |
269 | assert_equal NUM_REV, @repository.changesets.count |
|
269 | assert_equal NUM_REV, @repository.changesets.count | |
270 | # Full diff of changeset 2f9c0091 |
|
270 | # Full diff of changeset 2f9c0091 | |
271 | ['inline', 'sbs'].each do |dt| |
|
271 | ['inline', 'sbs'].each do |dt| | |
272 | get :diff, |
|
272 | get :diff, | |
273 | :id => PRJ_ID, |
|
273 | :id => PRJ_ID, | |
274 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', |
|
274 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', | |
275 | :type => dt |
|
275 | :type => dt | |
276 | assert_response :success |
|
276 | assert_response :success | |
277 | assert_template 'diff' |
|
277 | assert_template 'diff' | |
278 | # Line 22 removed |
|
278 | # Line 22 removed | |
279 | assert_tag :tag => 'th', |
|
279 | assert_tag :tag => 'th', | |
280 | :content => /22/, |
|
280 | :content => /22/, | |
281 | :sibling => { :tag => 'td', |
|
281 | :sibling => { :tag => 'td', | |
282 | :attributes => { :class => /diff_out/ }, |
|
282 | :attributes => { :class => /diff_out/ }, | |
283 | :content => /def remove/ } |
|
283 | :content => /def remove/ } | |
284 | assert_tag :tag => 'h2', :content => /2f9c0091/ |
|
284 | assert_tag :tag => 'h2', :content => /2f9c0091/ | |
285 | end |
|
285 | end | |
286 | end |
|
286 | end | |
287 |
|
287 | |||
288 | def test_diff_truncated |
|
288 | def test_diff_truncated | |
289 | assert_equal 0, @repository.changesets.count |
|
289 | assert_equal 0, @repository.changesets.count | |
290 | @repository.fetch_changesets |
|
290 | @repository.fetch_changesets | |
291 | @project.reload |
|
291 | @project.reload | |
292 | assert_equal NUM_REV, @repository.changesets.count |
|
292 | assert_equal NUM_REV, @repository.changesets.count | |
293 |
|
293 | |||
294 | with_settings :diff_max_lines_displayed => 5 do |
|
294 | with_settings :diff_max_lines_displayed => 5 do | |
295 | # Truncated diff of changeset 2f9c0091 |
|
295 | # Truncated diff of changeset 2f9c0091 | |
296 | with_cache do |
|
296 | with_cache do | |
297 | get :diff, :id => PRJ_ID, :type => 'inline', |
|
297 | get :diff, :id => PRJ_ID, :type => 'inline', | |
298 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
|
298 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' | |
299 | assert_response :success |
|
299 | assert_response :success | |
300 | assert @response.body.include?("... This diff was truncated") |
|
300 | assert @response.body.include?("... This diff was truncated") | |
301 |
|
301 | |||
302 | Setting.default_language = 'fr' |
|
302 | Setting.default_language = 'fr' | |
303 | get :diff, :id => PRJ_ID, :type => 'inline', |
|
303 | get :diff, :id => PRJ_ID, :type => 'inline', | |
304 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
|
304 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' | |
305 | assert_response :success |
|
305 | assert_response :success | |
306 | assert ! @response.body.include?("... This diff was truncated") |
|
306 | assert ! @response.body.include?("... This diff was truncated") | |
307 | assert @response.body.include?("... Ce diff") |
|
307 | assert @response.body.include?("... Ce diff") | |
308 | end |
|
308 | end | |
309 | end |
|
309 | end | |
310 | end |
|
310 | end | |
311 |
|
311 | |||
312 | def test_diff_two_revs |
|
312 | def test_diff_two_revs | |
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 | ['inline', 'sbs'].each do |dt| |
|
317 | ['inline', 'sbs'].each do |dt| | |
318 | get :diff, |
|
318 | get :diff, | |
319 | :id => PRJ_ID, |
|
319 | :id => PRJ_ID, | |
320 | :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
320 | :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', | |
321 | :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', |
|
321 | :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', | |
322 | :type => dt |
|
322 | :type => dt | |
323 | assert_response :success |
|
323 | assert_response :success | |
324 | assert_template 'diff' |
|
324 | assert_template 'diff' | |
325 | diff = assigns(:diff) |
|
325 | diff = assigns(:diff) | |
326 | assert_not_nil diff |
|
326 | assert_not_nil diff | |
327 | assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/ |
|
327 | assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/ | |
328 | end |
|
328 | end | |
329 | end |
|
329 | end | |
330 |
|
330 | |||
331 | def test_diff_latin_1 |
|
331 | def test_diff_latin_1 | |
332 | if @ruby19_non_utf8_pass |
|
332 | if @ruby19_non_utf8_pass | |
333 | puts_ruby19_non_utf8_pass() |
|
333 | puts_ruby19_non_utf8_pass() | |
334 | else |
|
334 | else | |
335 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
335 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
336 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| |
|
336 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| | |
337 | ['inline', 'sbs'].each do |dt| |
|
337 | ['inline', 'sbs'].each do |dt| | |
338 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
338 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt | |
339 | assert_response :success |
|
339 | assert_response :success | |
340 | assert_template 'diff' |
|
340 | assert_template 'diff' | |
341 | assert_tag :tag => 'thead', |
|
341 | assert_tag :tag => 'thead', | |
342 | :descendant => { |
|
342 | :descendant => { | |
343 | :tag => 'th', |
|
343 | :tag => 'th', | |
344 | :attributes => { :class => 'filename' } , |
|
344 | :attributes => { :class => 'filename' } , | |
345 | :content => /latin-1-dir\/test-#{@char_1}.txt/ , |
|
345 | :content => /latin-1-dir\/test-#{@char_1}.txt/ , | |
346 | }, |
|
346 | }, | |
347 | :sibling => { |
|
347 | :sibling => { | |
348 | :tag => 'tbody', |
|
348 | :tag => 'tbody', | |
349 | :descendant => { |
|
349 | :descendant => { | |
350 | :tag => 'td', |
|
350 | :tag => 'td', | |
351 | :attributes => { :class => /diff_in/ }, |
|
351 | :attributes => { :class => /diff_in/ }, | |
352 | :content => /test-#{@char_1}.txt/ |
|
352 | :content => /test-#{@char_1}.txt/ | |
353 | } |
|
353 | } | |
354 | } |
|
354 | } | |
355 | end |
|
355 | end | |
356 | end |
|
356 | end | |
357 | end |
|
357 | end | |
358 | end |
|
358 | end | |
359 | end |
|
359 | end | |
360 |
|
360 | |||
361 | def test_save_diff_type |
|
361 | def test_save_diff_type | |
362 | @request.session[:user_id] = 1 # admin |
|
362 | @request.session[:user_id] = 1 # admin | |
363 | user = User.find(1) |
|
363 | user = User.find(1) | |
364 | get :diff, |
|
364 | get :diff, | |
365 | :id => PRJ_ID, |
|
365 | :id => PRJ_ID, | |
366 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
|
366 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' | |
367 | assert_response :success |
|
367 | assert_response :success | |
368 | assert_template 'diff' |
|
368 | assert_template 'diff' | |
369 | user.reload |
|
369 | user.reload | |
370 | assert_equal "inline", user.pref[:diff_type] |
|
370 | assert_equal "inline", user.pref[:diff_type] | |
371 | get :diff, |
|
371 | get :diff, | |
372 | :id => PRJ_ID, |
|
372 | :id => PRJ_ID, | |
373 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', |
|
373 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', | |
374 | :type => 'sbs' |
|
374 | :type => 'sbs' | |
375 | assert_response :success |
|
375 | assert_response :success | |
376 | assert_template 'diff' |
|
376 | assert_template 'diff' | |
377 | user.reload |
|
377 | user.reload | |
378 | assert_equal "sbs", user.pref[:diff_type] |
|
378 | assert_equal "sbs", user.pref[:diff_type] | |
379 | end |
|
379 | end | |
380 |
|
380 | |||
381 | def test_annotate |
|
381 | def test_annotate | |
382 | get :annotate, :id => PRJ_ID, |
|
382 | get :annotate, :id => PRJ_ID, | |
383 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
383 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] | |
384 | assert_response :success |
|
384 | assert_response :success | |
385 | assert_template 'annotate' |
|
385 | assert_template 'annotate' | |
|
386 | ||||
386 | # Line 23, changeset 2f9c0091 |
|
387 | # Line 23, changeset 2f9c0091 | |
387 | assert_tag :tag => 'th', :content => '23', |
|
388 | assert_select 'tr' do | |
388 | :sibling => { |
|
389 | assert_select 'th.line-num', :text => '23' | |
389 | :tag => 'td', |
|
390 | assert_select 'td.revision', :text => /2f9c0091/ | |
390 | :child => { |
|
391 | assert_select 'td.author', :text => 'jsmith' | |
391 | :tag => 'a', |
|
392 | assert_select 'td', :text => /remove_watcher/ | |
392 | :content => /2f9c0091/ |
|
393 | end | |
393 | } |
|
|||
394 | } |
|
|||
395 | assert_tag :tag => 'th', :content => '23', |
|
|||
396 | :sibling => { :tag => 'td', :content => /jsmith/ } |
|
|||
397 | assert_tag :tag => 'th', :content => '23', |
|
|||
398 | :sibling => { |
|
|||
399 | :tag => 'td', |
|
|||
400 | :child => { |
|
|||
401 | :tag => 'a', |
|
|||
402 | :content => /2f9c0091/ |
|
|||
403 | } |
|
|||
404 | } |
|
|||
405 | assert_tag :tag => 'th', :content => '23', |
|
|||
406 | :sibling => { :tag => 'td', :content => /remove_watcher/ } |
|
|||
407 | end |
|
394 | end | |
408 |
|
395 | |||
409 | def test_annotate_at_given_revision |
|
396 | def test_annotate_at_given_revision | |
410 | assert_equal 0, @repository.changesets.count |
|
397 | assert_equal 0, @repository.changesets.count | |
411 | @repository.fetch_changesets |
|
398 | @repository.fetch_changesets | |
412 | @project.reload |
|
399 | @project.reload | |
413 | assert_equal NUM_REV, @repository.changesets.count |
|
400 | assert_equal NUM_REV, @repository.changesets.count | |
414 | get :annotate, :id => PRJ_ID, :rev => 'deff7', |
|
401 | get :annotate, :id => PRJ_ID, :rev => 'deff7', | |
415 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
402 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] | |
416 | assert_response :success |
|
403 | assert_response :success | |
417 | assert_template 'annotate' |
|
404 | assert_template 'annotate' | |
418 | assert_tag :tag => 'h2', :content => /@ deff712f/ |
|
405 | assert_tag :tag => 'h2', :content => /@ deff712f/ | |
419 | end |
|
406 | end | |
420 |
|
407 | |||
421 | def test_annotate_binary_file |
|
408 | def test_annotate_binary_file | |
422 | get :annotate, :id => PRJ_ID, |
|
409 | get :annotate, :id => PRJ_ID, | |
423 | :path => repository_path_hash(['images', 'edit.png'])[:param] |
|
410 | :path => repository_path_hash(['images', 'edit.png'])[:param] | |
424 | assert_response 500 |
|
411 | assert_response 500 | |
425 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, |
|
412 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, | |
426 | :content => /cannot be annotated/ |
|
413 | :content => /cannot be annotated/ | |
427 | end |
|
414 | end | |
428 |
|
415 | |||
429 | def test_annotate_error_when_too_big |
|
416 | def test_annotate_error_when_too_big | |
430 | with_settings :file_max_size_displayed => 1 do |
|
417 | with_settings :file_max_size_displayed => 1 do | |
431 | get :annotate, :id => PRJ_ID, |
|
418 | get :annotate, :id => PRJ_ID, | |
432 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], |
|
419 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], | |
433 | :rev => 'deff712f' |
|
420 | :rev => 'deff712f' | |
434 | assert_response 500 |
|
421 | assert_response 500 | |
435 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, |
|
422 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, | |
436 | :content => /exceeds the maximum text file size/ |
|
423 | :content => /exceeds the maximum text file size/ | |
437 |
|
424 | |||
438 | get :annotate, :id => PRJ_ID, |
|
425 | get :annotate, :id => PRJ_ID, | |
439 | :path => repository_path_hash(['README'])[:param], |
|
426 | :path => repository_path_hash(['README'])[:param], | |
440 | :rev => '7234cb2' |
|
427 | :rev => '7234cb2' | |
441 | assert_response :success |
|
428 | assert_response :success | |
442 | assert_template 'annotate' |
|
429 | assert_template 'annotate' | |
443 | end |
|
430 | end | |
444 | end |
|
431 | end | |
445 |
|
432 | |||
446 | def test_annotate_latin_1 |
|
433 | def test_annotate_latin_1 | |
447 | if @ruby19_non_utf8_pass |
|
434 | if @ruby19_non_utf8_pass | |
448 | puts_ruby19_non_utf8_pass() |
|
435 | puts_ruby19_non_utf8_pass() | |
449 | elsif WINDOWS_PASS |
|
436 | elsif WINDOWS_PASS | |
450 | puts WINDOWS_SKIP_STR |
|
437 | puts WINDOWS_SKIP_STR | |
451 | elsif JRUBY_SKIP |
|
438 | elsif JRUBY_SKIP | |
452 | puts JRUBY_SKIP_STR |
|
439 | puts JRUBY_SKIP_STR | |
453 | else |
|
440 | else | |
454 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
441 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
455 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| |
|
442 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| | |
456 | get :annotate, :id => PRJ_ID, |
|
443 | get :annotate, :id => PRJ_ID, | |
457 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], |
|
444 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], | |
458 | :rev => r1 |
|
445 | :rev => r1 | |
459 | assert_tag :tag => 'th', |
|
446 | assert_tag :tag => 'th', | |
460 | :content => '1', |
|
447 | :content => '1', | |
461 | :attributes => { :class => 'line-num' }, |
|
448 | :attributes => { :class => 'line-num' }, | |
462 | :sibling => { :tag => 'td', |
|
449 | :sibling => { :tag => 'td', | |
463 | :content => /test-#{@char_1}.txt/ } |
|
450 | :content => /test-#{@char_1}.txt/ } | |
464 | end |
|
451 | end | |
465 | end |
|
452 | end | |
466 | end |
|
453 | end | |
467 | end |
|
454 | end | |
468 |
|
455 | |||
469 | def test_revision |
|
456 | def test_revision | |
470 | assert_equal 0, @repository.changesets.count |
|
457 | assert_equal 0, @repository.changesets.count | |
471 | @repository.fetch_changesets |
|
458 | @repository.fetch_changesets | |
472 | @project.reload |
|
459 | @project.reload | |
473 | assert_equal NUM_REV, @repository.changesets.count |
|
460 | assert_equal NUM_REV, @repository.changesets.count | |
474 | ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r| |
|
461 | ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r| | |
475 | get :revision, :id => PRJ_ID, :rev => r |
|
462 | get :revision, :id => PRJ_ID, :rev => r | |
476 | assert_response :success |
|
463 | assert_response :success | |
477 | assert_template 'revision' |
|
464 | assert_template 'revision' | |
478 | end |
|
465 | end | |
479 | end |
|
466 | end | |
480 |
|
467 | |||
481 | def test_empty_revision |
|
468 | def test_empty_revision | |
482 | assert_equal 0, @repository.changesets.count |
|
469 | assert_equal 0, @repository.changesets.count | |
483 | @repository.fetch_changesets |
|
470 | @repository.fetch_changesets | |
484 | @project.reload |
|
471 | @project.reload | |
485 | assert_equal NUM_REV, @repository.changesets.count |
|
472 | assert_equal NUM_REV, @repository.changesets.count | |
486 | ['', ' ', nil].each do |r| |
|
473 | ['', ' ', nil].each do |r| | |
487 | get :revision, :id => PRJ_ID, :rev => r |
|
474 | get :revision, :id => PRJ_ID, :rev => r | |
488 | assert_response 404 |
|
475 | assert_response 404 | |
489 | assert_error_tag :content => /was not found/ |
|
476 | assert_error_tag :content => /was not found/ | |
490 | end |
|
477 | end | |
491 | end |
|
478 | end | |
492 |
|
479 | |||
493 | def test_destroy_valid_repository |
|
480 | def test_destroy_valid_repository | |
494 | @request.session[:user_id] = 1 # admin |
|
481 | @request.session[:user_id] = 1 # admin | |
495 | assert_equal 0, @repository.changesets.count |
|
482 | assert_equal 0, @repository.changesets.count | |
496 | @repository.fetch_changesets |
|
483 | @repository.fetch_changesets | |
497 | @project.reload |
|
484 | @project.reload | |
498 | assert_equal NUM_REV, @repository.changesets.count |
|
485 | assert_equal NUM_REV, @repository.changesets.count | |
499 |
|
486 | |||
500 | assert_difference 'Repository.count', -1 do |
|
487 | assert_difference 'Repository.count', -1 do | |
501 | delete :destroy, :id => @repository.id |
|
488 | delete :destroy, :id => @repository.id | |
502 | end |
|
489 | end | |
503 | assert_response 302 |
|
490 | assert_response 302 | |
504 | @project.reload |
|
491 | @project.reload | |
505 | assert_nil @project.repository |
|
492 | assert_nil @project.repository | |
506 | end |
|
493 | end | |
507 |
|
494 | |||
508 | def test_destroy_invalid_repository |
|
495 | def test_destroy_invalid_repository | |
509 | @request.session[:user_id] = 1 # admin |
|
496 | @request.session[:user_id] = 1 # admin | |
510 | @project.repository.destroy |
|
497 | @project.repository.destroy | |
511 | @repository = Repository::Git.create!( |
|
498 | @repository = Repository::Git.create!( | |
512 | :project => @project, |
|
499 | :project => @project, | |
513 | :url => "/invalid", |
|
500 | :url => "/invalid", | |
514 | :path_encoding => 'ISO-8859-1' |
|
501 | :path_encoding => 'ISO-8859-1' | |
515 | ) |
|
502 | ) | |
516 | @repository.fetch_changesets |
|
503 | @repository.fetch_changesets | |
517 | @repository.reload |
|
504 | @repository.reload | |
518 | assert_equal 0, @repository.changesets.count |
|
505 | assert_equal 0, @repository.changesets.count | |
519 |
|
506 | |||
520 | assert_difference 'Repository.count', -1 do |
|
507 | assert_difference 'Repository.count', -1 do | |
521 | delete :destroy, :id => @repository.id |
|
508 | delete :destroy, :id => @repository.id | |
522 | end |
|
509 | end | |
523 | assert_response 302 |
|
510 | assert_response 302 | |
524 | @project.reload |
|
511 | @project.reload | |
525 | assert_nil @project.repository |
|
512 | assert_nil @project.repository | |
526 | end |
|
513 | end | |
527 |
|
514 | |||
528 | private |
|
515 | private | |
529 |
|
516 | |||
530 | def puts_ruby19_non_utf8_pass |
|
517 | def puts_ruby19_non_utf8_pass | |
531 | puts "TODO: This test fails in Ruby 1.9 " + |
|
518 | puts "TODO: This test fails in Ruby 1.9 " + | |
532 | "and Encoding.default_external is not UTF-8. " + |
|
519 | "and Encoding.default_external is not UTF-8. " + | |
533 | "Current value is '#{Encoding.default_external.to_s}'" |
|
520 | "Current value is '#{Encoding.default_external.to_s}'" | |
534 | end |
|
521 | end | |
535 | else |
|
522 | else | |
536 | puts "Git test repository NOT FOUND. Skipping functional tests !!!" |
|
523 | puts "Git test repository NOT FOUND. Skipping functional tests !!!" | |
537 | def test_fake; assert true end |
|
524 | def test_fake; assert true end | |
538 | end |
|
525 | end | |
539 |
|
526 | |||
540 | private |
|
527 | private | |
541 | def with_cache(&block) |
|
528 | def with_cache(&block) | |
542 | before = ActionController::Base.perform_caching |
|
529 | before = ActionController::Base.perform_caching | |
543 | ActionController::Base.perform_caching = true |
|
530 | ActionController::Base.perform_caching = true | |
544 | block.call |
|
531 | block.call | |
545 | ActionController::Base.perform_caching = before |
|
532 | ActionController::Base.perform_caching = before | |
546 | end |
|
533 | end | |
547 | end |
|
534 | end |
@@ -1,526 +1,511 | |||||
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 RepositoriesMercurialControllerTest < ActionController::TestCase |
|
20 | class RepositoriesMercurialControllerTest < 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/mercurial_repository').to_s |
|
26 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s | |
27 | CHAR_1_HEX = "\xc3\x9c" |
|
27 | CHAR_1_HEX = "\xc3\x9c" | |
28 | PRJ_ID = 3 |
|
28 | PRJ_ID = 3 | |
29 | NUM_REV = 32 |
|
29 | NUM_REV = 32 | |
30 |
|
30 | |||
31 | ruby19_non_utf8_pass = |
|
31 | ruby19_non_utf8_pass = | |
32 | (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') |
|
32 | (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') | |
33 |
|
33 | |||
34 | def setup |
|
34 | def setup | |
35 | User.current = nil |
|
35 | User.current = nil | |
36 | @project = Project.find(PRJ_ID) |
|
36 | @project = Project.find(PRJ_ID) | |
37 | @repository = Repository::Mercurial.create( |
|
37 | @repository = Repository::Mercurial.create( | |
38 | :project => @project, |
|
38 | :project => @project, | |
39 | :url => REPOSITORY_PATH, |
|
39 | :url => REPOSITORY_PATH, | |
40 | :path_encoding => 'ISO-8859-1' |
|
40 | :path_encoding => 'ISO-8859-1' | |
41 | ) |
|
41 | ) | |
42 | assert @repository |
|
42 | assert @repository | |
43 | @diff_c_support = true |
|
43 | @diff_c_support = true | |
44 | @char_1 = CHAR_1_HEX.dup |
|
44 | @char_1 = CHAR_1_HEX.dup | |
45 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" |
|
45 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" | |
46 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" |
|
46 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" | |
47 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" |
|
47 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" | |
48 | if @char_1.respond_to?(:force_encoding) |
|
48 | if @char_1.respond_to?(:force_encoding) | |
49 | @char_1.force_encoding('UTF-8') |
|
49 | @char_1.force_encoding('UTF-8') | |
50 | @tag_char_1.force_encoding('UTF-8') |
|
50 | @tag_char_1.force_encoding('UTF-8') | |
51 | @branch_char_0.force_encoding('UTF-8') |
|
51 | @branch_char_0.force_encoding('UTF-8') | |
52 | @branch_char_1.force_encoding('UTF-8') |
|
52 | @branch_char_1.force_encoding('UTF-8') | |
53 | end |
|
53 | end | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | if ruby19_non_utf8_pass |
|
56 | if ruby19_non_utf8_pass | |
57 | puts "TODO: Mercurial functional test fails in Ruby 1.9 " + |
|
57 | puts "TODO: Mercurial functional test fails in Ruby 1.9 " + | |
58 | "and Encoding.default_external is not UTF-8. " + |
|
58 | "and Encoding.default_external is not UTF-8. " + | |
59 | "Current value is '#{Encoding.default_external.to_s}'" |
|
59 | "Current value is '#{Encoding.default_external.to_s}'" | |
60 | def test_fake; assert true end |
|
60 | def test_fake; assert true end | |
61 | elsif File.directory?(REPOSITORY_PATH) |
|
61 | elsif File.directory?(REPOSITORY_PATH) | |
62 |
|
62 | |||
63 | def test_get_new |
|
63 | def test_get_new | |
64 | @request.session[:user_id] = 1 |
|
64 | @request.session[:user_id] = 1 | |
65 | @project.repository.destroy |
|
65 | @project.repository.destroy | |
66 | get :new, :project_id => 'subproject1', :repository_scm => 'Mercurial' |
|
66 | get :new, :project_id => 'subproject1', :repository_scm => 'Mercurial' | |
67 | assert_response :success |
|
67 | assert_response :success | |
68 | assert_template 'new' |
|
68 | assert_template 'new' | |
69 | assert_kind_of Repository::Mercurial, assigns(:repository) |
|
69 | assert_kind_of Repository::Mercurial, assigns(:repository) | |
70 | assert assigns(:repository).new_record? |
|
70 | assert assigns(:repository).new_record? | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def test_show_root |
|
73 | def test_show_root | |
74 | assert_equal 0, @repository.changesets.count |
|
74 | assert_equal 0, @repository.changesets.count | |
75 | @repository.fetch_changesets |
|
75 | @repository.fetch_changesets | |
76 | @project.reload |
|
76 | @project.reload | |
77 | assert_equal NUM_REV, @repository.changesets.count |
|
77 | assert_equal NUM_REV, @repository.changesets.count | |
78 | get :show, :id => PRJ_ID |
|
78 | get :show, :id => PRJ_ID | |
79 | assert_response :success |
|
79 | assert_response :success | |
80 | assert_template 'show' |
|
80 | assert_template 'show' | |
81 | assert_not_nil assigns(:entries) |
|
81 | assert_not_nil assigns(:entries) | |
82 | assert_equal 4, assigns(:entries).size |
|
82 | assert_equal 4, assigns(:entries).size | |
83 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
83 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} | |
84 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
84 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} | |
85 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
85 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} | |
86 | assert_not_nil assigns(:changesets) |
|
86 | assert_not_nil assigns(:changesets) | |
87 | assert assigns(:changesets).size > 0 |
|
87 | assert assigns(:changesets).size > 0 | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | def test_show_directory |
|
90 | def test_show_directory | |
91 | assert_equal 0, @repository.changesets.count |
|
91 | assert_equal 0, @repository.changesets.count | |
92 | @repository.fetch_changesets |
|
92 | @repository.fetch_changesets | |
93 | @project.reload |
|
93 | @project.reload | |
94 | assert_equal NUM_REV, @repository.changesets.count |
|
94 | assert_equal NUM_REV, @repository.changesets.count | |
95 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param] |
|
95 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param] | |
96 | assert_response :success |
|
96 | assert_response :success | |
97 | assert_template 'show' |
|
97 | assert_template 'show' | |
98 | assert_not_nil assigns(:entries) |
|
98 | assert_not_nil assigns(:entries) | |
99 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
99 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
100 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
100 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
101 | assert_not_nil entry |
|
101 | assert_not_nil entry | |
102 | assert_equal 'file', entry.kind |
|
102 | assert_equal 'file', entry.kind | |
103 | assert_equal 'images/edit.png', entry.path |
|
103 | assert_equal 'images/edit.png', entry.path | |
104 | assert_not_nil assigns(:changesets) |
|
104 | assert_not_nil assigns(:changesets) | |
105 | assert assigns(:changesets).size > 0 |
|
105 | assert assigns(:changesets).size > 0 | |
106 | end |
|
106 | end | |
107 |
|
107 | |||
108 | def test_show_at_given_revision |
|
108 | def test_show_at_given_revision | |
109 | assert_equal 0, @repository.changesets.count |
|
109 | assert_equal 0, @repository.changesets.count | |
110 | @repository.fetch_changesets |
|
110 | @repository.fetch_changesets | |
111 | @project.reload |
|
111 | @project.reload | |
112 | assert_equal NUM_REV, @repository.changesets.count |
|
112 | assert_equal NUM_REV, @repository.changesets.count | |
113 | [0, '0', '0885933ad4f6'].each do |r1| |
|
113 | [0, '0', '0885933ad4f6'].each do |r1| | |
114 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param], |
|
114 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param], | |
115 | :rev => r1 |
|
115 | :rev => r1 | |
116 | assert_response :success |
|
116 | assert_response :success | |
117 | assert_template 'show' |
|
117 | assert_template 'show' | |
118 | assert_not_nil assigns(:entries) |
|
118 | assert_not_nil assigns(:entries) | |
119 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
119 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |
120 | assert_not_nil assigns(:changesets) |
|
120 | assert_not_nil assigns(:changesets) | |
121 | assert assigns(:changesets).size > 0 |
|
121 | assert assigns(:changesets).size > 0 | |
122 | end |
|
122 | end | |
123 | end |
|
123 | end | |
124 |
|
124 | |||
125 | def test_show_directory_sql_escape_percent |
|
125 | def test_show_directory_sql_escape_percent | |
126 | assert_equal 0, @repository.changesets.count |
|
126 | assert_equal 0, @repository.changesets.count | |
127 | @repository.fetch_changesets |
|
127 | @repository.fetch_changesets | |
128 | @project.reload |
|
128 | @project.reload | |
129 | assert_equal NUM_REV, @repository.changesets.count |
|
129 | assert_equal NUM_REV, @repository.changesets.count | |
130 | [13, '13', '3a330eb32958'].each do |r1| |
|
130 | [13, '13', '3a330eb32958'].each do |r1| | |
131 | get :show, :id => PRJ_ID, |
|
131 | get :show, :id => PRJ_ID, | |
132 | :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param], |
|
132 | :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param], | |
133 | :rev => r1 |
|
133 | :rev => r1 | |
134 | assert_response :success |
|
134 | assert_response :success | |
135 | assert_template 'show' |
|
135 | assert_template 'show' | |
136 |
|
136 | |||
137 | assert_not_nil assigns(:entries) |
|
137 | assert_not_nil assigns(:entries) | |
138 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], |
|
138 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], | |
139 | assigns(:entries).collect(&:name) |
|
139 | assigns(:entries).collect(&:name) | |
140 | changesets = assigns(:changesets) |
|
140 | changesets = assigns(:changesets) | |
141 | assert_not_nil changesets |
|
141 | assert_not_nil changesets | |
142 | assert assigns(:changesets).size > 0 |
|
142 | assert assigns(:changesets).size > 0 | |
143 | assert_equal %w(13 11 10 9), changesets.collect(&:revision) |
|
143 | assert_equal %w(13 11 10 9), changesets.collect(&:revision) | |
144 | end |
|
144 | end | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | def test_show_directory_latin_1_path |
|
147 | def test_show_directory_latin_1_path | |
148 | assert_equal 0, @repository.changesets.count |
|
148 | assert_equal 0, @repository.changesets.count | |
149 | @repository.fetch_changesets |
|
149 | @repository.fetch_changesets | |
150 | @project.reload |
|
150 | @project.reload | |
151 | assert_equal NUM_REV, @repository.changesets.count |
|
151 | assert_equal NUM_REV, @repository.changesets.count | |
152 | [21, '21', 'adf805632193'].each do |r1| |
|
152 | [21, '21', 'adf805632193'].each do |r1| | |
153 | get :show, :id => PRJ_ID, |
|
153 | get :show, :id => PRJ_ID, | |
154 | :path => repository_path_hash(['latin-1-dir'])[:param], |
|
154 | :path => repository_path_hash(['latin-1-dir'])[:param], | |
155 | :rev => r1 |
|
155 | :rev => r1 | |
156 | assert_response :success |
|
156 | assert_response :success | |
157 | assert_template 'show' |
|
157 | assert_template 'show' | |
158 |
|
158 | |||
159 | assert_not_nil assigns(:entries) |
|
159 | assert_not_nil assigns(:entries) | |
160 | assert_equal ["make-latin-1-file.rb", |
|
160 | assert_equal ["make-latin-1-file.rb", | |
161 | "test-#{@char_1}-1.txt", |
|
161 | "test-#{@char_1}-1.txt", | |
162 | "test-#{@char_1}-2.txt", |
|
162 | "test-#{@char_1}-2.txt", | |
163 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) |
|
163 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) | |
164 | changesets = assigns(:changesets) |
|
164 | changesets = assigns(:changesets) | |
165 | assert_not_nil changesets |
|
165 | assert_not_nil changesets | |
166 | assert_equal %w(21 20 19 18 17), changesets.collect(&:revision) |
|
166 | assert_equal %w(21 20 19 18 17), changesets.collect(&:revision) | |
167 | end |
|
167 | end | |
168 | end |
|
168 | end | |
169 |
|
169 | |||
170 | def show_should_show_branch_selection_form |
|
170 | def show_should_show_branch_selection_form | |
171 | @repository.fetch_changesets |
|
171 | @repository.fetch_changesets | |
172 | @project.reload |
|
172 | @project.reload | |
173 | get :show, :id => PRJ_ID |
|
173 | get :show, :id => PRJ_ID | |
174 | assert_tag 'form', :attributes => {:id => 'revision_selector', :action => '/projects/subproject1/repository/show'} |
|
174 | assert_tag 'form', :attributes => {:id => 'revision_selector', :action => '/projects/subproject1/repository/show'} | |
175 | assert_tag 'select', :attributes => {:name => 'branch'}, |
|
175 | assert_tag 'select', :attributes => {:name => 'branch'}, | |
176 | :child => {:tag => 'option', :attributes => {:value => 'test-branch-01'}}, |
|
176 | :child => {:tag => 'option', :attributes => {:value => 'test-branch-01'}}, | |
177 | :parent => {:tag => 'form', :attributes => {:id => 'revision_selector'}} |
|
177 | :parent => {:tag => 'form', :attributes => {:id => 'revision_selector'}} | |
178 | end |
|
178 | end | |
179 |
|
179 | |||
180 | def test_show_branch |
|
180 | def test_show_branch | |
181 | assert_equal 0, @repository.changesets.count |
|
181 | assert_equal 0, @repository.changesets.count | |
182 | @repository.fetch_changesets |
|
182 | @repository.fetch_changesets | |
183 | @project.reload |
|
183 | @project.reload | |
184 | assert_equal NUM_REV, @repository.changesets.count |
|
184 | assert_equal NUM_REV, @repository.changesets.count | |
185 | [ |
|
185 | [ | |
186 | 'default', |
|
186 | 'default', | |
187 | @branch_char_1, |
|
187 | @branch_char_1, | |
188 | 'branch (1)[2]&,%.-3_4', |
|
188 | 'branch (1)[2]&,%.-3_4', | |
189 | @branch_char_0, |
|
189 | @branch_char_0, | |
190 | 'test_branch.latin-1', |
|
190 | 'test_branch.latin-1', | |
191 | 'test-branch-00', |
|
191 | 'test-branch-00', | |
192 | ].each do |bra| |
|
192 | ].each do |bra| | |
193 | get :show, :id => PRJ_ID, :rev => bra |
|
193 | get :show, :id => PRJ_ID, :rev => bra | |
194 | assert_response :success |
|
194 | assert_response :success | |
195 | assert_template 'show' |
|
195 | assert_template 'show' | |
196 | assert_not_nil assigns(:entries) |
|
196 | assert_not_nil assigns(:entries) | |
197 | assert assigns(:entries).size > 0 |
|
197 | assert assigns(:entries).size > 0 | |
198 | assert_not_nil assigns(:changesets) |
|
198 | assert_not_nil assigns(:changesets) | |
199 | assert assigns(:changesets).size > 0 |
|
199 | assert assigns(:changesets).size > 0 | |
200 | end |
|
200 | end | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | def test_show_tag |
|
203 | def test_show_tag | |
204 | assert_equal 0, @repository.changesets.count |
|
204 | assert_equal 0, @repository.changesets.count | |
205 | @repository.fetch_changesets |
|
205 | @repository.fetch_changesets | |
206 | @project.reload |
|
206 | @project.reload | |
207 | assert_equal NUM_REV, @repository.changesets.count |
|
207 | assert_equal NUM_REV, @repository.changesets.count | |
208 | [ |
|
208 | [ | |
209 | @tag_char_1, |
|
209 | @tag_char_1, | |
210 | 'tag_test.00', |
|
210 | 'tag_test.00', | |
211 | 'tag-init-revision' |
|
211 | 'tag-init-revision' | |
212 | ].each do |tag| |
|
212 | ].each do |tag| | |
213 | get :show, :id => PRJ_ID, :rev => tag |
|
213 | get :show, :id => PRJ_ID, :rev => tag | |
214 | assert_response :success |
|
214 | assert_response :success | |
215 | assert_template 'show' |
|
215 | assert_template 'show' | |
216 | assert_not_nil assigns(:entries) |
|
216 | assert_not_nil assigns(:entries) | |
217 | assert assigns(:entries).size > 0 |
|
217 | assert assigns(:entries).size > 0 | |
218 | assert_not_nil assigns(:changesets) |
|
218 | assert_not_nil assigns(:changesets) | |
219 | assert assigns(:changesets).size > 0 |
|
219 | assert assigns(:changesets).size > 0 | |
220 | end |
|
220 | end | |
221 | end |
|
221 | end | |
222 |
|
222 | |||
223 | def test_changes |
|
223 | def test_changes | |
224 | get :changes, :id => PRJ_ID, |
|
224 | get :changes, :id => PRJ_ID, | |
225 | :path => repository_path_hash(['images', 'edit.png'])[:param] |
|
225 | :path => repository_path_hash(['images', 'edit.png'])[:param] | |
226 | assert_response :success |
|
226 | assert_response :success | |
227 | assert_template 'changes' |
|
227 | assert_template 'changes' | |
228 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
228 | assert_tag :tag => 'h2', :content => 'edit.png' | |
229 | end |
|
229 | end | |
230 |
|
230 | |||
231 | def test_entry_show |
|
231 | def test_entry_show | |
232 | get :entry, :id => PRJ_ID, |
|
232 | get :entry, :id => PRJ_ID, | |
233 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
233 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] | |
234 | assert_response :success |
|
234 | assert_response :success | |
235 | assert_template 'entry' |
|
235 | assert_template 'entry' | |
236 | # Line 10 |
|
236 | # Line 10 | |
237 | assert_tag :tag => 'th', |
|
237 | assert_tag :tag => 'th', | |
238 | :content => '10', |
|
238 | :content => '10', | |
239 | :attributes => { :class => 'line-num' }, |
|
239 | :attributes => { :class => 'line-num' }, | |
240 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
|
240 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } | |
241 | end |
|
241 | end | |
242 |
|
242 | |||
243 | def test_entry_show_latin_1_path |
|
243 | def test_entry_show_latin_1_path | |
244 | [21, '21', 'adf805632193'].each do |r1| |
|
244 | [21, '21', 'adf805632193'].each do |r1| | |
245 | get :entry, :id => PRJ_ID, |
|
245 | get :entry, :id => PRJ_ID, | |
246 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param], |
|
246 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param], | |
247 | :rev => r1 |
|
247 | :rev => r1 | |
248 | assert_response :success |
|
248 | assert_response :success | |
249 | assert_template 'entry' |
|
249 | assert_template 'entry' | |
250 | assert_tag :tag => 'th', |
|
250 | assert_tag :tag => 'th', | |
251 | :content => '1', |
|
251 | :content => '1', | |
252 | :attributes => { :class => 'line-num' }, |
|
252 | :attributes => { :class => 'line-num' }, | |
253 | :sibling => { :tag => 'td', |
|
253 | :sibling => { :tag => 'td', | |
254 | :content => /Mercurial is a distributed version control system/ } |
|
254 | :content => /Mercurial is a distributed version control system/ } | |
255 | end |
|
255 | end | |
256 | end |
|
256 | end | |
257 |
|
257 | |||
258 | def test_entry_show_latin_1_contents |
|
258 | def test_entry_show_latin_1_contents | |
259 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
259 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
260 | [27, '27', '7bbf4c738e71'].each do |r1| |
|
260 | [27, '27', '7bbf4c738e71'].each do |r1| | |
261 | get :entry, :id => PRJ_ID, |
|
261 | get :entry, :id => PRJ_ID, | |
262 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], |
|
262 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], | |
263 | :rev => r1 |
|
263 | :rev => r1 | |
264 | assert_response :success |
|
264 | assert_response :success | |
265 | assert_template 'entry' |
|
265 | assert_template 'entry' | |
266 | assert_tag :tag => 'th', |
|
266 | assert_tag :tag => 'th', | |
267 | :content => '1', |
|
267 | :content => '1', | |
268 | :attributes => { :class => 'line-num' }, |
|
268 | :attributes => { :class => 'line-num' }, | |
269 | :sibling => { :tag => 'td', |
|
269 | :sibling => { :tag => 'td', | |
270 | :content => /test-#{@char_1}.txt/ } |
|
270 | :content => /test-#{@char_1}.txt/ } | |
271 | end |
|
271 | end | |
272 | end |
|
272 | end | |
273 | end |
|
273 | end | |
274 |
|
274 | |||
275 | def test_entry_download |
|
275 | def test_entry_download | |
276 | get :entry, :id => PRJ_ID, |
|
276 | get :entry, :id => PRJ_ID, | |
277 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], |
|
277 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], | |
278 | :format => 'raw' |
|
278 | :format => 'raw' | |
279 | assert_response :success |
|
279 | assert_response :success | |
280 | # File content |
|
280 | # File content | |
281 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
|
281 | assert @response.body.include?('WITHOUT ANY WARRANTY') | |
282 | end |
|
282 | end | |
283 |
|
283 | |||
284 | def test_entry_binary_force_download |
|
284 | def test_entry_binary_force_download | |
285 | get :entry, :id => PRJ_ID, :rev => 1, |
|
285 | get :entry, :id => PRJ_ID, :rev => 1, | |
286 | :path => repository_path_hash(['images', 'edit.png'])[:param] |
|
286 | :path => repository_path_hash(['images', 'edit.png'])[:param] | |
287 | assert_response :success |
|
287 | assert_response :success | |
288 | assert_equal 'image/png', @response.content_type |
|
288 | assert_equal 'image/png', @response.content_type | |
289 | end |
|
289 | end | |
290 |
|
290 | |||
291 | def test_directory_entry |
|
291 | def test_directory_entry | |
292 | get :entry, :id => PRJ_ID, |
|
292 | get :entry, :id => PRJ_ID, | |
293 | :path => repository_path_hash(['sources'])[:param] |
|
293 | :path => repository_path_hash(['sources'])[:param] | |
294 | assert_response :success |
|
294 | assert_response :success | |
295 | assert_template 'show' |
|
295 | assert_template 'show' | |
296 | assert_not_nil assigns(:entry) |
|
296 | assert_not_nil assigns(:entry) | |
297 | assert_equal 'sources', assigns(:entry).name |
|
297 | assert_equal 'sources', assigns(:entry).name | |
298 | end |
|
298 | end | |
299 |
|
299 | |||
300 | def test_diff |
|
300 | def test_diff | |
301 | assert_equal 0, @repository.changesets.count |
|
301 | assert_equal 0, @repository.changesets.count | |
302 | @repository.fetch_changesets |
|
302 | @repository.fetch_changesets | |
303 | @project.reload |
|
303 | @project.reload | |
304 | assert_equal NUM_REV, @repository.changesets.count |
|
304 | assert_equal NUM_REV, @repository.changesets.count | |
305 | [4, '4', 'def6d2f1254a'].each do |r1| |
|
305 | [4, '4', 'def6d2f1254a'].each do |r1| | |
306 | # Full diff of changeset 4 |
|
306 | # Full diff of changeset 4 | |
307 | ['inline', 'sbs'].each do |dt| |
|
307 | ['inline', 'sbs'].each do |dt| | |
308 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
308 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt | |
309 | assert_response :success |
|
309 | assert_response :success | |
310 | assert_template 'diff' |
|
310 | assert_template 'diff' | |
311 | if @diff_c_support |
|
311 | if @diff_c_support | |
312 | # Line 22 removed |
|
312 | # Line 22 removed | |
313 | assert_tag :tag => 'th', |
|
313 | assert_tag :tag => 'th', | |
314 | :content => '22', |
|
314 | :content => '22', | |
315 | :sibling => { :tag => 'td', |
|
315 | :sibling => { :tag => 'td', | |
316 | :attributes => { :class => /diff_out/ }, |
|
316 | :attributes => { :class => /diff_out/ }, | |
317 | :content => /def remove/ } |
|
317 | :content => /def remove/ } | |
318 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ |
|
318 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ | |
319 | end |
|
319 | end | |
320 | end |
|
320 | end | |
321 | end |
|
321 | end | |
322 | end |
|
322 | end | |
323 |
|
323 | |||
324 | def test_diff_two_revs |
|
324 | def test_diff_two_revs | |
325 | assert_equal 0, @repository.changesets.count |
|
325 | assert_equal 0, @repository.changesets.count | |
326 | @repository.fetch_changesets |
|
326 | @repository.fetch_changesets | |
327 | @project.reload |
|
327 | @project.reload | |
328 | assert_equal NUM_REV, @repository.changesets.count |
|
328 | assert_equal NUM_REV, @repository.changesets.count | |
329 | [2, '400bb8672109', '400', 400].each do |r1| |
|
329 | [2, '400bb8672109', '400', 400].each do |r1| | |
330 | [4, 'def6d2f1254a'].each do |r2| |
|
330 | [4, 'def6d2f1254a'].each do |r2| | |
331 | ['inline', 'sbs'].each do |dt| |
|
331 | ['inline', 'sbs'].each do |dt| | |
332 | get :diff, |
|
332 | get :diff, | |
333 | :id => PRJ_ID, |
|
333 | :id => PRJ_ID, | |
334 | :rev => r1, |
|
334 | :rev => r1, | |
335 | :rev_to => r2, |
|
335 | :rev_to => r2, | |
336 | :type => dt |
|
336 | :type => dt | |
337 | assert_response :success |
|
337 | assert_response :success | |
338 | assert_template 'diff' |
|
338 | assert_template 'diff' | |
339 | diff = assigns(:diff) |
|
339 | diff = assigns(:diff) | |
340 | assert_not_nil diff |
|
340 | assert_not_nil diff | |
341 | assert_tag :tag => 'h2', |
|
341 | assert_tag :tag => 'h2', | |
342 | :content => /4:def6d2f1254a 2:400bb8672109/ |
|
342 | :content => /4:def6d2f1254a 2:400bb8672109/ | |
343 | end |
|
343 | end | |
344 | end |
|
344 | end | |
345 | end |
|
345 | end | |
346 | end |
|
346 | end | |
347 |
|
347 | |||
348 | def test_diff_latin_1_path |
|
348 | def test_diff_latin_1_path | |
349 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
349 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
350 | [21, 'adf805632193'].each do |r1| |
|
350 | [21, 'adf805632193'].each do |r1| | |
351 | ['inline', 'sbs'].each do |dt| |
|
351 | ['inline', 'sbs'].each do |dt| | |
352 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
352 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt | |
353 | assert_response :success |
|
353 | assert_response :success | |
354 | assert_template 'diff' |
|
354 | assert_template 'diff' | |
355 | assert_tag :tag => 'thead', |
|
355 | assert_tag :tag => 'thead', | |
356 | :descendant => { |
|
356 | :descendant => { | |
357 | :tag => 'th', |
|
357 | :tag => 'th', | |
358 | :attributes => { :class => 'filename' } , |
|
358 | :attributes => { :class => 'filename' } , | |
359 | :content => /latin-1-dir\/test-#{@char_1}-2.txt/ , |
|
359 | :content => /latin-1-dir\/test-#{@char_1}-2.txt/ , | |
360 | }, |
|
360 | }, | |
361 | :sibling => { |
|
361 | :sibling => { | |
362 | :tag => 'tbody', |
|
362 | :tag => 'tbody', | |
363 | :descendant => { |
|
363 | :descendant => { | |
364 | :tag => 'td', |
|
364 | :tag => 'td', | |
365 | :attributes => { :class => /diff_in/ }, |
|
365 | :attributes => { :class => /diff_in/ }, | |
366 | :content => /It is written in Python/ |
|
366 | :content => /It is written in Python/ | |
367 | } |
|
367 | } | |
368 | } |
|
368 | } | |
369 | end |
|
369 | end | |
370 | end |
|
370 | end | |
371 | end |
|
371 | end | |
372 | end |
|
372 | end | |
373 |
|
373 | |||
374 | def test_annotate |
|
374 | def test_annotate | |
375 | get :annotate, :id => PRJ_ID, |
|
375 | get :annotate, :id => PRJ_ID, | |
376 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
376 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] | |
377 | assert_response :success |
|
377 | assert_response :success | |
378 | assert_template 'annotate' |
|
378 | assert_template 'annotate' | |
|
379 | ||||
379 | # Line 22, revision 4:def6d2f1254a |
|
380 | # Line 22, revision 4:def6d2f1254a | |
380 |
assert_t |
|
381 | assert_select 'tr' do | |
381 | :content => '22', |
|
382 | assert_select 'th.line-num', :text => '22' | |
382 | :attributes => { :class => 'line-num' }, |
|
383 | assert_select 'td.revision', :text => '4:def6d2f1254a' | |
383 | :sibling => |
|
384 | assert_select 'td.author', :text => 'jsmith' | |
384 | { |
|
385 | assert_select 'td', :text => /remove_watcher/ | |
385 | :tag => 'td', |
|
386 | end | |
386 | :attributes => { :class => 'revision' }, |
|
|||
387 | :child => { :tag => 'a', :content => '4:def6d2f1254a' } |
|
|||
388 | } |
|
|||
389 | assert_tag :tag => 'th', |
|
|||
390 | :content => '22', |
|
|||
391 | :attributes => { :class => 'line-num' }, |
|
|||
392 | :sibling => |
|
|||
393 | { |
|
|||
394 | :tag => 'td' , |
|
|||
395 | :content => 'jsmith' , |
|
|||
396 | :attributes => { :class => 'author' }, |
|
|||
397 | } |
|
|||
398 | assert_tag :tag => 'th', |
|
|||
399 | :content => '22', |
|
|||
400 | :attributes => { :class => 'line-num' }, |
|
|||
401 | :sibling => { :tag => 'td', :content => /remove_watcher/ } |
|
|||
402 | end |
|
387 | end | |
403 |
|
388 | |||
404 | def test_annotate_not_in_tip |
|
389 | def test_annotate_not_in_tip | |
405 | assert_equal 0, @repository.changesets.count |
|
390 | assert_equal 0, @repository.changesets.count | |
406 | @repository.fetch_changesets |
|
391 | @repository.fetch_changesets | |
407 | @project.reload |
|
392 | @project.reload | |
408 | assert_equal NUM_REV, @repository.changesets.count |
|
393 | assert_equal NUM_REV, @repository.changesets.count | |
409 | get :annotate, :id => PRJ_ID, |
|
394 | get :annotate, :id => PRJ_ID, | |
410 | :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param] |
|
395 | :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param] | |
411 | assert_response 404 |
|
396 | assert_response 404 | |
412 | assert_error_tag :content => /was not found/ |
|
397 | assert_error_tag :content => /was not found/ | |
413 | end |
|
398 | end | |
414 |
|
399 | |||
415 | def test_annotate_at_given_revision |
|
400 | def test_annotate_at_given_revision | |
416 | assert_equal 0, @repository.changesets.count |
|
401 | assert_equal 0, @repository.changesets.count | |
417 | @repository.fetch_changesets |
|
402 | @repository.fetch_changesets | |
418 | @project.reload |
|
403 | @project.reload | |
419 | assert_equal NUM_REV, @repository.changesets.count |
|
404 | assert_equal NUM_REV, @repository.changesets.count | |
420 | [2, '400bb8672109', '400', 400].each do |r1| |
|
405 | [2, '400bb8672109', '400', 400].each do |r1| | |
421 | get :annotate, :id => PRJ_ID, :rev => r1, |
|
406 | get :annotate, :id => PRJ_ID, :rev => r1, | |
422 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
407 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] | |
423 | assert_response :success |
|
408 | assert_response :success | |
424 | assert_template 'annotate' |
|
409 | assert_template 'annotate' | |
425 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ |
|
410 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ | |
426 | end |
|
411 | end | |
427 | end |
|
412 | end | |
428 |
|
413 | |||
429 | def test_annotate_latin_1_path |
|
414 | def test_annotate_latin_1_path | |
430 | [21, '21', 'adf805632193'].each do |r1| |
|
415 | [21, '21', 'adf805632193'].each do |r1| | |
431 | get :annotate, :id => PRJ_ID, |
|
416 | get :annotate, :id => PRJ_ID, | |
432 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param], |
|
417 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param], | |
433 | :rev => r1 |
|
418 | :rev => r1 | |
434 | assert_response :success |
|
419 | assert_response :success | |
435 | assert_template 'annotate' |
|
420 | assert_template 'annotate' | |
436 | assert_tag :tag => 'th', |
|
421 | assert_tag :tag => 'th', | |
437 | :content => '1', |
|
422 | :content => '1', | |
438 | :attributes => { :class => 'line-num' }, |
|
423 | :attributes => { :class => 'line-num' }, | |
439 | :sibling => |
|
424 | :sibling => | |
440 | { |
|
425 | { | |
441 | :tag => 'td', |
|
426 | :tag => 'td', | |
442 | :attributes => { :class => 'revision' }, |
|
427 | :attributes => { :class => 'revision' }, | |
443 | :child => { :tag => 'a', :content => '20:709858aafd1b' } |
|
428 | :child => { :tag => 'a', :content => '20:709858aafd1b' } | |
444 | } |
|
429 | } | |
445 | assert_tag :tag => 'th', |
|
430 | assert_tag :tag => 'th', | |
446 | :content => '1', |
|
431 | :content => '1', | |
447 | :attributes => { :class => 'line-num' }, |
|
432 | :attributes => { :class => 'line-num' }, | |
448 | :sibling => |
|
433 | :sibling => | |
449 | { |
|
434 | { | |
450 | :tag => 'td' , |
|
435 | :tag => 'td' , | |
451 | :content => 'jsmith' , |
|
436 | :content => 'jsmith' , | |
452 | :attributes => { :class => 'author' }, |
|
437 | :attributes => { :class => 'author' }, | |
453 | } |
|
438 | } | |
454 | assert_tag :tag => 'th', |
|
439 | assert_tag :tag => 'th', | |
455 | :content => '1', |
|
440 | :content => '1', | |
456 | :attributes => { :class => 'line-num' }, |
|
441 | :attributes => { :class => 'line-num' }, | |
457 | :sibling => { :tag => 'td', |
|
442 | :sibling => { :tag => 'td', | |
458 | :content => /Mercurial is a distributed version control system/ } |
|
443 | :content => /Mercurial is a distributed version control system/ } | |
459 |
|
444 | |||
460 | end |
|
445 | end | |
461 | end |
|
446 | end | |
462 |
|
447 | |||
463 | def test_annotate_latin_1_contents |
|
448 | def test_annotate_latin_1_contents | |
464 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
449 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
465 | [27, '7bbf4c738e71'].each do |r1| |
|
450 | [27, '7bbf4c738e71'].each do |r1| | |
466 | get :annotate, :id => PRJ_ID, |
|
451 | get :annotate, :id => PRJ_ID, | |
467 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], |
|
452 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], | |
468 | :rev => r1 |
|
453 | :rev => r1 | |
469 | assert_tag :tag => 'th', |
|
454 | assert_tag :tag => 'th', | |
470 | :content => '1', |
|
455 | :content => '1', | |
471 | :attributes => { :class => 'line-num' }, |
|
456 | :attributes => { :class => 'line-num' }, | |
472 | :sibling => { :tag => 'td', |
|
457 | :sibling => { :tag => 'td', | |
473 | :content => /test-#{@char_1}.txt/ } |
|
458 | :content => /test-#{@char_1}.txt/ } | |
474 | end |
|
459 | end | |
475 | end |
|
460 | end | |
476 | end |
|
461 | end | |
477 |
|
462 | |||
478 | def test_empty_revision |
|
463 | def test_empty_revision | |
479 | assert_equal 0, @repository.changesets.count |
|
464 | assert_equal 0, @repository.changesets.count | |
480 | @repository.fetch_changesets |
|
465 | @repository.fetch_changesets | |
481 | @project.reload |
|
466 | @project.reload | |
482 | assert_equal NUM_REV, @repository.changesets.count |
|
467 | assert_equal NUM_REV, @repository.changesets.count | |
483 | ['', ' ', nil].each do |r| |
|
468 | ['', ' ', nil].each do |r| | |
484 | get :revision, :id => PRJ_ID, :rev => r |
|
469 | get :revision, :id => PRJ_ID, :rev => r | |
485 | assert_response 404 |
|
470 | assert_response 404 | |
486 | assert_error_tag :content => /was not found/ |
|
471 | assert_error_tag :content => /was not found/ | |
487 | end |
|
472 | end | |
488 | end |
|
473 | end | |
489 |
|
474 | |||
490 | def test_destroy_valid_repository |
|
475 | def test_destroy_valid_repository | |
491 | @request.session[:user_id] = 1 # admin |
|
476 | @request.session[:user_id] = 1 # admin | |
492 | assert_equal 0, @repository.changesets.count |
|
477 | assert_equal 0, @repository.changesets.count | |
493 | @repository.fetch_changesets |
|
478 | @repository.fetch_changesets | |
494 | assert_equal NUM_REV, @repository.changesets.count |
|
479 | assert_equal NUM_REV, @repository.changesets.count | |
495 |
|
480 | |||
496 | assert_difference 'Repository.count', -1 do |
|
481 | assert_difference 'Repository.count', -1 do | |
497 | delete :destroy, :id => @repository.id |
|
482 | delete :destroy, :id => @repository.id | |
498 | end |
|
483 | end | |
499 | assert_response 302 |
|
484 | assert_response 302 | |
500 | @project.reload |
|
485 | @project.reload | |
501 | assert_nil @project.repository |
|
486 | assert_nil @project.repository | |
502 | end |
|
487 | end | |
503 |
|
488 | |||
504 | def test_destroy_invalid_repository |
|
489 | def test_destroy_invalid_repository | |
505 | @request.session[:user_id] = 1 # admin |
|
490 | @request.session[:user_id] = 1 # admin | |
506 | @project.repository.destroy |
|
491 | @project.repository.destroy | |
507 | @repository = Repository::Mercurial.create!( |
|
492 | @repository = Repository::Mercurial.create!( | |
508 | :project => Project.find(PRJ_ID), |
|
493 | :project => Project.find(PRJ_ID), | |
509 | :url => "/invalid", |
|
494 | :url => "/invalid", | |
510 | :path_encoding => 'ISO-8859-1' |
|
495 | :path_encoding => 'ISO-8859-1' | |
511 | ) |
|
496 | ) | |
512 | @repository.fetch_changesets |
|
497 | @repository.fetch_changesets | |
513 | assert_equal 0, @repository.changesets.count |
|
498 | assert_equal 0, @repository.changesets.count | |
514 |
|
499 | |||
515 | assert_difference 'Repository.count', -1 do |
|
500 | assert_difference 'Repository.count', -1 do | |
516 | delete :destroy, :id => @repository.id |
|
501 | delete :destroy, :id => @repository.id | |
517 | end |
|
502 | end | |
518 | assert_response 302 |
|
503 | assert_response 302 | |
519 | @project.reload |
|
504 | @project.reload | |
520 | assert_nil @project.repository |
|
505 | assert_nil @project.repository | |
521 | end |
|
506 | end | |
522 | else |
|
507 | else | |
523 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" |
|
508 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" | |
524 | def test_fake; assert true end |
|
509 | def test_fake; assert true end | |
525 | end |
|
510 | end | |
526 | end |
|
511 | end |
General Comments 0
You need to be logged in to leave comments.
Login now