##// END OF EJS Templates
scm: subversion: run both of "inline" and "side by side" diff in functional test_revision_diff test....
Toshi MARUYAMA -
r5861:cb555d988505
parent child
Show More
@@ -1,297 +1,299
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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 require 'repositories_controller'
19 require 'repositories_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
23
24 class RepositoriesSubversionControllerTest < ActionController::TestCase
24 class RepositoriesSubversionControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
26 :repositories, :issues, :issue_statuses, :changesets, :changes,
26 :repositories, :issues, :issue_statuses, :changesets, :changes,
27 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
27 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
28
28
29 PRJ_ID = 3
29 PRJ_ID = 3
30
30
31 def setup
31 def setup
32 @controller = RepositoriesController.new
32 @controller = RepositoriesController.new
33 @request = ActionController::TestRequest.new
33 @request = ActionController::TestRequest.new
34 @response = ActionController::TestResponse.new
34 @response = ActionController::TestResponse.new
35 Setting.default_language = 'en'
35 Setting.default_language = 'en'
36 User.current = nil
36 User.current = nil
37
37
38 @project = Project.find(PRJ_ID)
38 @project = Project.find(PRJ_ID)
39 @repository = Repository::Subversion.create(:project => @project,
39 @repository = Repository::Subversion.create(:project => @project,
40 :url => self.class.subversion_repository_url)
40 :url => self.class.subversion_repository_url)
41 assert @repository
41 assert @repository
42 end
42 end
43
43
44 if repository_configured?('subversion')
44 if repository_configured?('subversion')
45 def test_show
45 def test_show
46 @repository.fetch_changesets
46 @repository.fetch_changesets
47 @repository.reload
47 @repository.reload
48 get :show, :id => PRJ_ID
48 get :show, :id => PRJ_ID
49 assert_response :success
49 assert_response :success
50 assert_template 'show'
50 assert_template 'show'
51 assert_not_nil assigns(:entries)
51 assert_not_nil assigns(:entries)
52 assert_not_nil assigns(:changesets)
52 assert_not_nil assigns(:changesets)
53 end
53 end
54
54
55 def test_browse_root
55 def test_browse_root
56 @repository.fetch_changesets
56 @repository.fetch_changesets
57 @repository.reload
57 @repository.reload
58 get :show, :id => PRJ_ID
58 get :show, :id => PRJ_ID
59 assert_response :success
59 assert_response :success
60 assert_template 'show'
60 assert_template 'show'
61 assert_not_nil assigns(:entries)
61 assert_not_nil assigns(:entries)
62 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
62 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
63 assert_equal 'dir', entry.kind
63 assert_equal 'dir', entry.kind
64 end
64 end
65
65
66 def test_browse_directory
66 def test_browse_directory
67 @repository.fetch_changesets
67 @repository.fetch_changesets
68 @repository.reload
68 @repository.reload
69 get :show, :id => PRJ_ID, :path => ['subversion_test']
69 get :show, :id => PRJ_ID, :path => ['subversion_test']
70 assert_response :success
70 assert_response :success
71 assert_template 'show'
71 assert_template 'show'
72 assert_not_nil assigns(:entries)
72 assert_not_nil assigns(:entries)
73 assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'],
73 assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'],
74 assigns(:entries).collect(&:name)
74 assigns(:entries).collect(&:name)
75 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
75 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
76 assert_equal 'file', entry.kind
76 assert_equal 'file', entry.kind
77 assert_equal 'subversion_test/helloworld.c', entry.path
77 assert_equal 'subversion_test/helloworld.c', entry.path
78 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
78 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
79 end
79 end
80
80
81 def test_browse_at_given_revision
81 def test_browse_at_given_revision
82 @repository.fetch_changesets
82 @repository.fetch_changesets
83 @repository.reload
83 @repository.reload
84 get :show, :id => PRJ_ID, :path => ['subversion_test'], :rev => 4
84 get :show, :id => PRJ_ID, :path => ['subversion_test'], :rev => 4
85 assert_response :success
85 assert_response :success
86 assert_template 'show'
86 assert_template 'show'
87 assert_not_nil assigns(:entries)
87 assert_not_nil assigns(:entries)
88 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'],
88 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'],
89 assigns(:entries).collect(&:name)
89 assigns(:entries).collect(&:name)
90 end
90 end
91
91
92 def test_file_changes
92 def test_file_changes
93 @repository.fetch_changesets
93 @repository.fetch_changesets
94 @repository.reload
94 @repository.reload
95 get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder', 'helloworld.rb' ]
95 get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder', 'helloworld.rb' ]
96 assert_response :success
96 assert_response :success
97 assert_template 'changes'
97 assert_template 'changes'
98
98
99 changesets = assigns(:changesets)
99 changesets = assigns(:changesets)
100 assert_not_nil changesets
100 assert_not_nil changesets
101 assert_equal %w(6 3 2), changesets.collect(&:revision)
101 assert_equal %w(6 3 2), changesets.collect(&:revision)
102
102
103 # svn properties displayed with svn >= 1.5 only
103 # svn properties displayed with svn >= 1.5 only
104 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
104 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
105 assert_not_nil assigns(:properties)
105 assert_not_nil assigns(:properties)
106 assert_equal 'native', assigns(:properties)['svn:eol-style']
106 assert_equal 'native', assigns(:properties)['svn:eol-style']
107 assert_tag :ul,
107 assert_tag :ul,
108 :child => { :tag => 'li',
108 :child => { :tag => 'li',
109 :child => { :tag => 'b', :content => 'svn:eol-style' },
109 :child => { :tag => 'b', :content => 'svn:eol-style' },
110 :child => { :tag => 'span', :content => 'native' } }
110 :child => { :tag => 'span', :content => 'native' } }
111 end
111 end
112 end
112 end
113
113
114 def test_directory_changes
114 def test_directory_changes
115 @repository.fetch_changesets
115 @repository.fetch_changesets
116 @repository.reload
116 @repository.reload
117 get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder' ]
117 get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder' ]
118 assert_response :success
118 assert_response :success
119 assert_template 'changes'
119 assert_template 'changes'
120
120
121 changesets = assigns(:changesets)
121 changesets = assigns(:changesets)
122 assert_not_nil changesets
122 assert_not_nil changesets
123 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
123 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
124 end
124 end
125
125
126 def test_entry
126 def test_entry
127 @repository.fetch_changesets
127 @repository.fetch_changesets
128 @repository.reload
128 @repository.reload
129 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c']
129 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c']
130 assert_response :success
130 assert_response :success
131 assert_template 'entry'
131 assert_template 'entry'
132 end
132 end
133
133
134 def test_entry_should_send_if_too_big
134 def test_entry_should_send_if_too_big
135 @repository.fetch_changesets
135 @repository.fetch_changesets
136 @repository.reload
136 @repository.reload
137 # no files in the test repo is larger than 1KB...
137 # no files in the test repo is larger than 1KB...
138 with_settings :file_max_size_displayed => 0 do
138 with_settings :file_max_size_displayed => 0 do
139 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c']
139 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c']
140 assert_response :success
140 assert_response :success
141 assert_template ''
141 assert_template ''
142 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
142 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
143 end
143 end
144 end
144 end
145
145
146 def test_entry_at_given_revision
146 def test_entry_at_given_revision
147 @repository.fetch_changesets
147 @repository.fetch_changesets
148 @repository.reload
148 @repository.reload
149 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.rb'], :rev => 2
149 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.rb'], :rev => 2
150 assert_response :success
150 assert_response :success
151 assert_template 'entry'
151 assert_template 'entry'
152 # this line was removed in r3 and file was moved in r6
152 # this line was removed in r3 and file was moved in r6
153 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
153 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
154 :content => /Here's the code/
154 :content => /Here's the code/
155 end
155 end
156
156
157 def test_entry_not_found
157 def test_entry_not_found
158 @repository.fetch_changesets
158 @repository.fetch_changesets
159 @repository.reload
159 @repository.reload
160 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'zzz.c']
160 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'zzz.c']
161 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
161 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
162 :content => /The entry or revision was not found in the repository/
162 :content => /The entry or revision was not found in the repository/
163 end
163 end
164
164
165 def test_entry_download
165 def test_entry_download
166 @repository.fetch_changesets
166 @repository.fetch_changesets
167 @repository.reload
167 @repository.reload
168 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'], :format => 'raw'
168 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'], :format => 'raw'
169 assert_response :success
169 assert_response :success
170 assert_template ''
170 assert_template ''
171 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
171 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
172 end
172 end
173
173
174 def test_directory_entry
174 def test_directory_entry
175 @repository.fetch_changesets
175 @repository.fetch_changesets
176 @repository.reload
176 @repository.reload
177 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'folder']
177 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'folder']
178 assert_response :success
178 assert_response :success
179 assert_template 'show'
179 assert_template 'show'
180 assert_not_nil assigns(:entry)
180 assert_not_nil assigns(:entry)
181 assert_equal 'folder', assigns(:entry).name
181 assert_equal 'folder', assigns(:entry).name
182 end
182 end
183
183
184 # TODO: this test needs fixtures.
184 # TODO: this test needs fixtures.
185 def test_revision
185 def test_revision
186 @repository.fetch_changesets
186 @repository.fetch_changesets
187 @repository.reload
187 @repository.reload
188 get :revision, :id => 1, :rev => 2
188 get :revision, :id => 1, :rev => 2
189 assert_response :success
189 assert_response :success
190 assert_template 'revision'
190 assert_template 'revision'
191 assert_tag :tag => 'ul',
191 assert_tag :tag => 'ul',
192 :child => { :tag => 'li',
192 :child => { :tag => 'li',
193 # link to the entry at rev 2
193 # link to the entry at rev 2
194 :child => { :tag => 'a',
194 :child => { :tag => 'a',
195 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
195 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
196 :content => 'repo',
196 :content => 'repo',
197 # link to partial diff
197 # link to partial diff
198 :sibling => { :tag => 'a',
198 :sibling => { :tag => 'a',
199 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
199 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
200 }
200 }
201 }
201 }
202 }
202 }
203 end
203 end
204
204
205 def test_invalid_revision
205 def test_invalid_revision
206 @repository.fetch_changesets
206 @repository.fetch_changesets
207 @repository.reload
207 @repository.reload
208 get :revision, :id => PRJ_ID, :rev => 'something_weird'
208 get :revision, :id => PRJ_ID, :rev => 'something_weird'
209 assert_response 404
209 assert_response 404
210 assert_error_tag :content => /was not found/
210 assert_error_tag :content => /was not found/
211 end
211 end
212
212
213 def test_invalid_revision_diff
213 def test_invalid_revision_diff
214 get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird'
214 get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird'
215 assert_response 404
215 assert_response 404
216 assert_error_tag :content => /was not found/
216 assert_error_tag :content => /was not found/
217 end
217 end
218
218
219 def test_empty_revision
219 def test_empty_revision
220 @repository.fetch_changesets
220 @repository.fetch_changesets
221 @repository.reload
221 @repository.reload
222 ['', ' ', nil].each do |r|
222 ['', ' ', nil].each do |r|
223 get :revision, :id => PRJ_ID, :rev => r
223 get :revision, :id => PRJ_ID, :rev => r
224 assert_response 404
224 assert_response 404
225 assert_error_tag :content => /was not found/
225 assert_error_tag :content => /was not found/
226 end
226 end
227 end
227 end
228
228
229 # TODO: this test needs fixtures.
229 # TODO: this test needs fixtures.
230 def test_revision_with_repository_pointing_to_a_subdirectory
230 def test_revision_with_repository_pointing_to_a_subdirectory
231 r = Project.find(1).repository
231 r = Project.find(1).repository
232 # Changes repository url to a subdirectory
232 # Changes repository url to a subdirectory
233 r.update_attribute :url, (r.url + '/test/some')
233 r.update_attribute :url, (r.url + '/test/some')
234
234
235 get :revision, :id => 1, :rev => 2
235 get :revision, :id => 1, :rev => 2
236 assert_response :success
236 assert_response :success
237 assert_template 'revision'
237 assert_template 'revision'
238 assert_tag :tag => 'ul',
238 assert_tag :tag => 'ul',
239 :child => { :tag => 'li',
239 :child => { :tag => 'li',
240 # link to the entry at rev 2
240 # link to the entry at rev 2
241 :child => { :tag => 'a',
241 :child => { :tag => 'a',
242 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
242 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
243 :content => 'repo',
243 :content => 'repo',
244 # link to partial diff
244 # link to partial diff
245 :sibling => { :tag => 'a',
245 :sibling => { :tag => 'a',
246 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
246 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
247 }
247 }
248 }
248 }
249 }
249 }
250 end
250 end
251
251
252 def test_revision_diff
252 def test_revision_diff
253 @repository.fetch_changesets
253 @repository.fetch_changesets
254 @repository.reload
254 @repository.reload
255 get :diff, :id => PRJ_ID, :rev => 3
255 ['inline', 'sbs'].each do |dt|
256 assert_response :success
256 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
257 assert_template 'diff'
257 assert_response :success
258
258 assert_template 'diff'
259 assert_tag :tag => 'h2', :content => /3/
259 assert_tag :tag => 'h2',
260 :content => / 3/
261 end
260 end
262 end
261
263
262 def test_directory_diff
264 def test_directory_diff
263 @repository.fetch_changesets
265 @repository.fetch_changesets
264 @repository.reload
266 @repository.reload
265 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder']
267 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder']
266 assert_response :success
268 assert_response :success
267 assert_template 'diff'
269 assert_template 'diff'
268
270
269 diff = assigns(:diff)
271 diff = assigns(:diff)
270 assert_not_nil diff
272 assert_not_nil diff
271 # 2 files modified
273 # 2 files modified
272 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
274 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
273
275
274 assert_tag :tag => 'h2', :content => /2:6/
276 assert_tag :tag => 'h2', :content => /2:6/
275 end
277 end
276
278
277 def test_annotate
279 def test_annotate
278 @repository.fetch_changesets
280 @repository.fetch_changesets
279 @repository.reload
281 @repository.reload
280 get :annotate, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c']
282 get :annotate, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c']
281 assert_response :success
283 assert_response :success
282 assert_template 'annotate'
284 assert_template 'annotate'
283 end
285 end
284
286
285 def test_annotate_at_given_revision
287 def test_annotate_at_given_revision
286 @repository.fetch_changesets
288 @repository.fetch_changesets
287 @repository.reload
289 @repository.reload
288 get :annotate, :id => PRJ_ID, :rev => 8, :path => ['subversion_test', 'helloworld.c']
290 get :annotate, :id => PRJ_ID, :rev => 8, :path => ['subversion_test', 'helloworld.c']
289 assert_response :success
291 assert_response :success
290 assert_template 'annotate'
292 assert_template 'annotate'
291 assert_tag :tag => 'h2', :content => /@ 8/
293 assert_tag :tag => 'h2', :content => /@ 8/
292 end
294 end
293 else
295 else
294 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
296 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
295 def test_fake; assert true end
297 def test_fake; assert true end
296 end
298 end
297 end
299 end
General Comments 0
You need to be logged in to leave comments. Login now