##// END OF EJS Templates
Adds assertions for subversion annotate....
Jean-Philippe Lang -
r9924:cc79feabe2d1
parent child
Show More
@@ -1,418 +1,431
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 RepositoriesSubversionControllerTest < ActionController::TestCase
20 class RepositoriesSubversionControllerTest < ActionController::TestCase
21 tests RepositoriesController
21 tests RepositoriesController
22
22
23 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
23 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
24 :repositories, :issues, :issue_statuses, :changesets, :changes,
24 :repositories, :issues, :issue_statuses, :changesets, :changes,
25 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
25 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
26
26
27 PRJ_ID = 3
27 PRJ_ID = 3
28 NUM_REV = 11
28 NUM_REV = 11
29
29
30 def setup
30 def setup
31 Setting.default_language = 'en'
31 Setting.default_language = 'en'
32 User.current = nil
32 User.current = nil
33
33
34 @project = Project.find(PRJ_ID)
34 @project = Project.find(PRJ_ID)
35 @repository = Repository::Subversion.create(:project => @project,
35 @repository = Repository::Subversion.create(:project => @project,
36 :url => self.class.subversion_repository_url)
36 :url => self.class.subversion_repository_url)
37 assert @repository
37 assert @repository
38 end
38 end
39
39
40 if repository_configured?('subversion')
40 if repository_configured?('subversion')
41 def test_new
41 def test_new
42 @request.session[:user_id] = 1
42 @request.session[:user_id] = 1
43 @project.repository.destroy
43 @project.repository.destroy
44 get :new, :project_id => 'subproject1', :repository_scm => 'Subversion'
44 get :new, :project_id => 'subproject1', :repository_scm => 'Subversion'
45 assert_response :success
45 assert_response :success
46 assert_template 'new'
46 assert_template 'new'
47 assert_kind_of Repository::Subversion, assigns(:repository)
47 assert_kind_of Repository::Subversion, assigns(:repository)
48 assert assigns(:repository).new_record?
48 assert assigns(:repository).new_record?
49 end
49 end
50
50
51 def test_show
51 def test_show
52 assert_equal 0, @repository.changesets.count
52 assert_equal 0, @repository.changesets.count
53 @repository.fetch_changesets
53 @repository.fetch_changesets
54 @project.reload
54 @project.reload
55 assert_equal NUM_REV, @repository.changesets.count
55 assert_equal NUM_REV, @repository.changesets.count
56 get :show, :id => PRJ_ID
56 get :show, :id => PRJ_ID
57 assert_response :success
57 assert_response :success
58 assert_template 'show'
58 assert_template 'show'
59 assert_not_nil assigns(:entries)
59 assert_not_nil assigns(:entries)
60 assert_not_nil assigns(:changesets)
60 assert_not_nil assigns(:changesets)
61
61
62 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
62 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
63 assert_not_nil entry
63 assert_not_nil entry
64 assert_equal 'dir', entry.kind
64 assert_equal 'dir', entry.kind
65 assert_select 'tr.dir a[href=/projects/subproject1/repository/show/subversion_test]'
65 assert_select 'tr.dir a[href=/projects/subproject1/repository/show/subversion_test]'
66
66
67 assert_tag 'input', :attributes => {:name => 'rev'}
67 assert_tag 'input', :attributes => {:name => 'rev'}
68 assert_tag 'a', :content => 'Statistics'
68 assert_tag 'a', :content => 'Statistics'
69 assert_tag 'a', :content => 'Atom'
69 assert_tag 'a', :content => 'Atom'
70 assert_tag :tag => 'a',
70 assert_tag :tag => 'a',
71 :attributes => {:href => '/projects/subproject1/repository'},
71 :attributes => {:href => '/projects/subproject1/repository'},
72 :content => 'root'
72 :content => 'root'
73 end
73 end
74
74
75 def test_show_non_default
75 def test_show_non_default
76 Repository::Subversion.create(:project => @project,
76 Repository::Subversion.create(:project => @project,
77 :url => self.class.subversion_repository_url,
77 :url => self.class.subversion_repository_url,
78 :is_default => false, :identifier => 'svn')
78 :is_default => false, :identifier => 'svn')
79
79
80 get :show, :id => PRJ_ID, :repository_id => 'svn'
80 get :show, :id => PRJ_ID, :repository_id => 'svn'
81 assert_response :success
81 assert_response :success
82 assert_template 'show'
82 assert_template 'show'
83 assert_select 'tr.dir a[href=/projects/subproject1/repository/svn/show/subversion_test]'
83 assert_select 'tr.dir a[href=/projects/subproject1/repository/svn/show/subversion_test]'
84 # Repository menu should link to the main repo
84 # Repository menu should link to the main repo
85 assert_select '#main-menu a[href=/projects/subproject1/repository]'
85 assert_select '#main-menu a[href=/projects/subproject1/repository]'
86 end
86 end
87
87
88 def test_browse_directory
88 def test_browse_directory
89 assert_equal 0, @repository.changesets.count
89 assert_equal 0, @repository.changesets.count
90 @repository.fetch_changesets
90 @repository.fetch_changesets
91 @project.reload
91 @project.reload
92 assert_equal NUM_REV, @repository.changesets.count
92 assert_equal NUM_REV, @repository.changesets.count
93 get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param]
93 get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param]
94 assert_response :success
94 assert_response :success
95 assert_template 'show'
95 assert_template 'show'
96 assert_not_nil assigns(:entries)
96 assert_not_nil assigns(:entries)
97 assert_equal [
97 assert_equal [
98 '[folder_with_brackets]', 'folder', '.project',
98 '[folder_with_brackets]', 'folder', '.project',
99 'helloworld.c', 'textfile.txt'
99 'helloworld.c', 'textfile.txt'
100 ],
100 ],
101 assigns(:entries).collect(&:name)
101 assigns(:entries).collect(&:name)
102 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
102 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
103 assert_equal 'file', entry.kind
103 assert_equal 'file', entry.kind
104 assert_equal 'subversion_test/helloworld.c', entry.path
104 assert_equal 'subversion_test/helloworld.c', entry.path
105 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
105 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
106 end
106 end
107
107
108 def test_browse_at_given_revision
108 def test_browse_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 get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param],
113 get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param],
114 :rev => 4
114 :rev => 4
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 ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'],
118 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'],
119 assigns(:entries).collect(&:name)
119 assigns(:entries).collect(&:name)
120 end
120 end
121
121
122 def test_file_changes
122 def test_file_changes
123 assert_equal 0, @repository.changesets.count
123 assert_equal 0, @repository.changesets.count
124 @repository.fetch_changesets
124 @repository.fetch_changesets
125 @project.reload
125 @project.reload
126 assert_equal NUM_REV, @repository.changesets.count
126 assert_equal NUM_REV, @repository.changesets.count
127 get :changes, :id => PRJ_ID,
127 get :changes, :id => PRJ_ID,
128 :path => repository_path_hash(['subversion_test', 'folder', 'helloworld.rb'])[:param]
128 :path => repository_path_hash(['subversion_test', 'folder', 'helloworld.rb'])[:param]
129 assert_response :success
129 assert_response :success
130 assert_template 'changes'
130 assert_template 'changes'
131
131
132 changesets = assigns(:changesets)
132 changesets = assigns(:changesets)
133 assert_not_nil changesets
133 assert_not_nil changesets
134 assert_equal %w(6 3 2), changesets.collect(&:revision)
134 assert_equal %w(6 3 2), changesets.collect(&:revision)
135
135
136 # svn properties displayed with svn >= 1.5 only
136 # svn properties displayed with svn >= 1.5 only
137 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
137 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
138 assert_not_nil assigns(:properties)
138 assert_not_nil assigns(:properties)
139 assert_equal 'native', assigns(:properties)['svn:eol-style']
139 assert_equal 'native', assigns(:properties)['svn:eol-style']
140 assert_tag :ul,
140 assert_tag :ul,
141 :child => { :tag => 'li',
141 :child => { :tag => 'li',
142 :child => { :tag => 'b', :content => 'svn:eol-style' },
142 :child => { :tag => 'b', :content => 'svn:eol-style' },
143 :child => { :tag => 'span', :content => 'native' } }
143 :child => { :tag => 'span', :content => 'native' } }
144 end
144 end
145 end
145 end
146
146
147 def test_directory_changes
147 def test_directory_changes
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 get :changes, :id => PRJ_ID,
152 get :changes, :id => PRJ_ID,
153 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
153 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
154 assert_response :success
154 assert_response :success
155 assert_template 'changes'
155 assert_template 'changes'
156
156
157 changesets = assigns(:changesets)
157 changesets = assigns(:changesets)
158 assert_not_nil changesets
158 assert_not_nil changesets
159 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
159 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
160 end
160 end
161
161
162 def test_entry
162 def test_entry
163 assert_equal 0, @repository.changesets.count
163 assert_equal 0, @repository.changesets.count
164 @repository.fetch_changesets
164 @repository.fetch_changesets
165 @project.reload
165 @project.reload
166 assert_equal NUM_REV, @repository.changesets.count
166 assert_equal NUM_REV, @repository.changesets.count
167 get :entry, :id => PRJ_ID,
167 get :entry, :id => PRJ_ID,
168 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
168 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
169 assert_response :success
169 assert_response :success
170 assert_template 'entry'
170 assert_template 'entry'
171 end
171 end
172
172
173 def test_entry_should_send_if_too_big
173 def test_entry_should_send_if_too_big
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 # no files in the test repo is larger than 1KB...
178 # no files in the test repo is larger than 1KB...
179 with_settings :file_max_size_displayed => 0 do
179 with_settings :file_max_size_displayed => 0 do
180 get :entry, :id => PRJ_ID,
180 get :entry, :id => PRJ_ID,
181 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
181 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
182 assert_response :success
182 assert_response :success
183 assert_equal 'attachment; filename="helloworld.c"',
183 assert_equal 'attachment; filename="helloworld.c"',
184 @response.headers['Content-Disposition']
184 @response.headers['Content-Disposition']
185 end
185 end
186 end
186 end
187
187
188 def test_entry_should_send_images_inline
188 def test_entry_should_send_images_inline
189 get :entry, :id => PRJ_ID,
189 get :entry, :id => PRJ_ID,
190 :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'rubylogo.gif'])[:param]
190 :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'rubylogo.gif'])[:param]
191 assert_response :success
191 assert_response :success
192 assert_equal 'inline; filename="rubylogo.gif"', response.headers['Content-Disposition']
192 assert_equal 'inline; filename="rubylogo.gif"', response.headers['Content-Disposition']
193 end
193 end
194
194
195 def test_entry_at_given_revision
195 def test_entry_at_given_revision
196 assert_equal 0, @repository.changesets.count
196 assert_equal 0, @repository.changesets.count
197 @repository.fetch_changesets
197 @repository.fetch_changesets
198 @project.reload
198 @project.reload
199 assert_equal NUM_REV, @repository.changesets.count
199 assert_equal NUM_REV, @repository.changesets.count
200 get :entry, :id => PRJ_ID,
200 get :entry, :id => PRJ_ID,
201 :path => repository_path_hash(['subversion_test', 'helloworld.rb'])[:param],
201 :path => repository_path_hash(['subversion_test', 'helloworld.rb'])[:param],
202 :rev => 2
202 :rev => 2
203 assert_response :success
203 assert_response :success
204 assert_template 'entry'
204 assert_template 'entry'
205 # this line was removed in r3 and file was moved in r6
205 # this line was removed in r3 and file was moved in r6
206 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
206 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
207 :content => /Here's the code/
207 :content => /Here's the code/
208 end
208 end
209
209
210 def test_entry_not_found
210 def test_entry_not_found
211 assert_equal 0, @repository.changesets.count
211 assert_equal 0, @repository.changesets.count
212 @repository.fetch_changesets
212 @repository.fetch_changesets
213 @project.reload
213 @project.reload
214 assert_equal NUM_REV, @repository.changesets.count
214 assert_equal NUM_REV, @repository.changesets.count
215 get :entry, :id => PRJ_ID,
215 get :entry, :id => PRJ_ID,
216 :path => repository_path_hash(['subversion_test', 'zzz.c'])[:param]
216 :path => repository_path_hash(['subversion_test', 'zzz.c'])[:param]
217 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
217 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
218 :content => /The entry or revision was not found in the repository/
218 :content => /The entry or revision was not found in the repository/
219 end
219 end
220
220
221 def test_entry_download
221 def test_entry_download
222 assert_equal 0, @repository.changesets.count
222 assert_equal 0, @repository.changesets.count
223 @repository.fetch_changesets
223 @repository.fetch_changesets
224 @project.reload
224 @project.reload
225 assert_equal NUM_REV, @repository.changesets.count
225 assert_equal NUM_REV, @repository.changesets.count
226 get :raw, :id => PRJ_ID,
226 get :raw, :id => PRJ_ID,
227 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
227 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
228 assert_response :success
228 assert_response :success
229 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
229 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
230 end
230 end
231
231
232 def test_directory_entry
232 def test_directory_entry
233 assert_equal 0, @repository.changesets.count
233 assert_equal 0, @repository.changesets.count
234 @repository.fetch_changesets
234 @repository.fetch_changesets
235 @project.reload
235 @project.reload
236 assert_equal NUM_REV, @repository.changesets.count
236 assert_equal NUM_REV, @repository.changesets.count
237 get :entry, :id => PRJ_ID,
237 get :entry, :id => PRJ_ID,
238 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
238 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
239 assert_response :success
239 assert_response :success
240 assert_template 'show'
240 assert_template 'show'
241 assert_not_nil assigns(:entry)
241 assert_not_nil assigns(:entry)
242 assert_equal 'folder', assigns(:entry).name
242 assert_equal 'folder', assigns(:entry).name
243 end
243 end
244
244
245 # TODO: this test needs fixtures.
245 # TODO: this test needs fixtures.
246 def test_revision
246 def test_revision
247 get :revision, :id => 1, :rev => 2
247 get :revision, :id => 1, :rev => 2
248 assert_response :success
248 assert_response :success
249 assert_template 'revision'
249 assert_template 'revision'
250 assert_tag :tag => 'ul',
250 assert_tag :tag => 'ul',
251 :child => { :tag => 'li',
251 :child => { :tag => 'li',
252 # link to the entry at rev 2
252 # link to the entry at rev 2
253 :child => { :tag => 'a',
253 :child => { :tag => 'a',
254 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
254 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
255 :content => 'repo',
255 :content => 'repo',
256 # link to partial diff
256 # link to partial diff
257 :sibling => { :tag => 'a',
257 :sibling => { :tag => 'a',
258 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
258 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
259 }
259 }
260 }
260 }
261 }
261 }
262 end
262 end
263
263
264 def test_invalid_revision
264 def test_invalid_revision
265 assert_equal 0, @repository.changesets.count
265 assert_equal 0, @repository.changesets.count
266 @repository.fetch_changesets
266 @repository.fetch_changesets
267 @project.reload
267 @project.reload
268 assert_equal NUM_REV, @repository.changesets.count
268 assert_equal NUM_REV, @repository.changesets.count
269 get :revision, :id => PRJ_ID, :rev => 'something_weird'
269 get :revision, :id => PRJ_ID, :rev => 'something_weird'
270 assert_response 404
270 assert_response 404
271 assert_error_tag :content => /was not found/
271 assert_error_tag :content => /was not found/
272 end
272 end
273
273
274 def test_invalid_revision_diff
274 def test_invalid_revision_diff
275 get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird'
275 get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird'
276 assert_response 404
276 assert_response 404
277 assert_error_tag :content => /was not found/
277 assert_error_tag :content => /was not found/
278 end
278 end
279
279
280 def test_empty_revision
280 def test_empty_revision
281 assert_equal 0, @repository.changesets.count
281 assert_equal 0, @repository.changesets.count
282 @repository.fetch_changesets
282 @repository.fetch_changesets
283 @project.reload
283 @project.reload
284 assert_equal NUM_REV, @repository.changesets.count
284 assert_equal NUM_REV, @repository.changesets.count
285 ['', ' ', nil].each do |r|
285 ['', ' ', nil].each do |r|
286 get :revision, :id => PRJ_ID, :rev => r
286 get :revision, :id => PRJ_ID, :rev => r
287 assert_response 404
287 assert_response 404
288 assert_error_tag :content => /was not found/
288 assert_error_tag :content => /was not found/
289 end
289 end
290 end
290 end
291
291
292 # TODO: this test needs fixtures.
292 # TODO: this test needs fixtures.
293 def test_revision_with_repository_pointing_to_a_subdirectory
293 def test_revision_with_repository_pointing_to_a_subdirectory
294 r = Project.find(1).repository
294 r = Project.find(1).repository
295 # Changes repository url to a subdirectory
295 # Changes repository url to a subdirectory
296 r.update_attribute :url, (r.url + '/test/some')
296 r.update_attribute :url, (r.url + '/test/some')
297
297
298 get :revision, :id => 1, :rev => 2
298 get :revision, :id => 1, :rev => 2
299 assert_response :success
299 assert_response :success
300 assert_template 'revision'
300 assert_template 'revision'
301 assert_tag :tag => 'ul',
301 assert_tag :tag => 'ul',
302 :child => { :tag => 'li',
302 :child => { :tag => 'li',
303 # link to the entry at rev 2
303 # link to the entry at rev 2
304 :child => { :tag => 'a',
304 :child => { :tag => 'a',
305 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
305 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
306 :content => 'repo',
306 :content => 'repo',
307 # link to partial diff
307 # link to partial diff
308 :sibling => { :tag => 'a',
308 :sibling => { :tag => 'a',
309 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
309 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
310 }
310 }
311 }
311 }
312 }
312 }
313 end
313 end
314
314
315 def test_revision_diff
315 def test_revision_diff
316 assert_equal 0, @repository.changesets.count
316 assert_equal 0, @repository.changesets.count
317 @repository.fetch_changesets
317 @repository.fetch_changesets
318 @project.reload
318 @project.reload
319 assert_equal NUM_REV, @repository.changesets.count
319 assert_equal NUM_REV, @repository.changesets.count
320 ['inline', 'sbs'].each do |dt|
320 ['inline', 'sbs'].each do |dt|
321 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
321 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
322 assert_response :success
322 assert_response :success
323 assert_template 'diff'
323 assert_template 'diff'
324 assert_tag :tag => 'h2',
324 assert_tag :tag => 'h2',
325 :content => / 3/
325 :content => / 3/
326 end
326 end
327 end
327 end
328
328
329 def test_revision_diff_raw_format
329 def test_revision_diff_raw_format
330 assert_equal 0, @repository.changesets.count
330 assert_equal 0, @repository.changesets.count
331 @repository.fetch_changesets
331 @repository.fetch_changesets
332 @project.reload
332 @project.reload
333 assert_equal NUM_REV, @repository.changesets.count
333 assert_equal NUM_REV, @repository.changesets.count
334
334
335 get :diff, :id => PRJ_ID, :rev => 3, :format => 'diff'
335 get :diff, :id => PRJ_ID, :rev => 3, :format => 'diff'
336 assert_response :success
336 assert_response :success
337 assert_equal 'text/x-patch', @response.content_type
337 assert_equal 'text/x-patch', @response.content_type
338 assert_equal 'Index: subversion_test/textfile.txt', @response.body.split(/\r?\n/).first
338 assert_equal 'Index: subversion_test/textfile.txt', @response.body.split(/\r?\n/).first
339 end
339 end
340
340
341 def test_directory_diff
341 def test_directory_diff
342 assert_equal 0, @repository.changesets.count
342 assert_equal 0, @repository.changesets.count
343 @repository.fetch_changesets
343 @repository.fetch_changesets
344 @project.reload
344 @project.reload
345 assert_equal NUM_REV, @repository.changesets.count
345 assert_equal NUM_REV, @repository.changesets.count
346 ['inline', 'sbs'].each do |dt|
346 ['inline', 'sbs'].each do |dt|
347 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2,
347 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2,
348 :path => repository_path_hash(['subversion_test', 'folder'])[:param],
348 :path => repository_path_hash(['subversion_test', 'folder'])[:param],
349 :type => dt
349 :type => dt
350 assert_response :success
350 assert_response :success
351 assert_template 'diff'
351 assert_template 'diff'
352
352
353 diff = assigns(:diff)
353 diff = assigns(:diff)
354 assert_not_nil diff
354 assert_not_nil diff
355 # 2 files modified
355 # 2 files modified
356 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
356 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
357 assert_tag :tag => 'h2', :content => /2:6/
357 assert_tag :tag => 'h2', :content => /2:6/
358 end
358 end
359 end
359 end
360
360
361 def test_annotate
361 def test_annotate
362 assert_equal 0, @repository.changesets.count
362 assert_equal 0, @repository.changesets.count
363 @repository.fetch_changesets
363 @repository.fetch_changesets
364 @project.reload
364 @project.reload
365 assert_equal NUM_REV, @repository.changesets.count
365 assert_equal NUM_REV, @repository.changesets.count
366 get :annotate, :id => PRJ_ID,
366 get :annotate, :id => PRJ_ID,
367 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
367 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
368 assert_response :success
368 assert_response :success
369 assert_template 'annotate'
369 assert_template 'annotate'
370
371 assert_select 'tr' do
372 assert_select 'th.line-num', :text => '1'
373 assert_select 'td.revision', :text => '4'
374 assert_select 'td.author', :text => 'jp'
375 assert_select 'td', :text => /stdio.h/
376 end
377 # Same revision
378 assert_select 'tr' do
379 assert_select 'th.line-num', :text => '2'
380 assert_select 'td.revision', :text => ''
381 assert_select 'td.author', :text => ''
382 end
370 end
383 end
371
384
372 def test_annotate_at_given_revision
385 def test_annotate_at_given_revision
373 assert_equal 0, @repository.changesets.count
386 assert_equal 0, @repository.changesets.count
374 @repository.fetch_changesets
387 @repository.fetch_changesets
375 @project.reload
388 @project.reload
376 assert_equal NUM_REV, @repository.changesets.count
389 assert_equal NUM_REV, @repository.changesets.count
377 get :annotate, :id => PRJ_ID, :rev => 8,
390 get :annotate, :id => PRJ_ID, :rev => 8,
378 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
391 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
379 assert_response :success
392 assert_response :success
380 assert_template 'annotate'
393 assert_template 'annotate'
381 assert_tag :tag => 'h2', :content => /@ 8/
394 assert_tag :tag => 'h2', :content => /@ 8/
382 end
395 end
383
396
384 def test_destroy_valid_repository
397 def test_destroy_valid_repository
385 @request.session[:user_id] = 1 # admin
398 @request.session[:user_id] = 1 # admin
386 assert_equal 0, @repository.changesets.count
399 assert_equal 0, @repository.changesets.count
387 @repository.fetch_changesets
400 @repository.fetch_changesets
388 assert_equal NUM_REV, @repository.changesets.count
401 assert_equal NUM_REV, @repository.changesets.count
389
402
390 assert_difference 'Repository.count', -1 do
403 assert_difference 'Repository.count', -1 do
391 delete :destroy, :id => @repository.id
404 delete :destroy, :id => @repository.id
392 end
405 end
393 assert_response 302
406 assert_response 302
394 @project.reload
407 @project.reload
395 assert_nil @project.repository
408 assert_nil @project.repository
396 end
409 end
397
410
398 def test_destroy_invalid_repository
411 def test_destroy_invalid_repository
399 @request.session[:user_id] = 1 # admin
412 @request.session[:user_id] = 1 # admin
400 @project.repository.destroy
413 @project.repository.destroy
401 @repository = Repository::Subversion.create!(
414 @repository = Repository::Subversion.create!(
402 :project => @project,
415 :project => @project,
403 :url => "file:///invalid")
416 :url => "file:///invalid")
404 @repository.fetch_changesets
417 @repository.fetch_changesets
405 assert_equal 0, @repository.changesets.count
418 assert_equal 0, @repository.changesets.count
406
419
407 assert_difference 'Repository.count', -1 do
420 assert_difference 'Repository.count', -1 do
408 delete :destroy, :id => @repository.id
421 delete :destroy, :id => @repository.id
409 end
422 end
410 assert_response 302
423 assert_response 302
411 @project.reload
424 @project.reload
412 assert_nil @project.repository
425 assert_nil @project.repository
413 end
426 end
414 else
427 else
415 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
428 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
416 def test_fake; assert true end
429 def test_fake; assert true end
417 end
430 end
418 end
431 end
General Comments 0
You need to be logged in to leave comments. Login now