##// END OF EJS Templates
scm: fix broken main repository 'root' link...
Toshi MARUYAMA -
r9430:d658ab22d60e
parent child
Show More
@@ -1,29 +1,31
1 <%= link_to(@repository.identifier.present? ? h(@repository.identifier) : 'root',
1 <%= link_to(@repository.identifier.present? ? h(@repository.identifier) : 'root',
2 :action => 'show', :id => @project, :repository_id => @repository.identifier_param, :path => '', :rev => @rev) %>
2 :action => 'show', :id => @project,
3 :repository_id => @repository.identifier_param,
4 :path => nil, :rev => @rev) %>
3 <%
5 <%
4 dirs = path.split('/')
6 dirs = path.split('/')
5 if 'file' == kind
7 if 'file' == kind
6 filename = dirs.pop
8 filename = dirs.pop
7 end
9 end
8 link_path = ''
10 link_path = ''
9 dirs.each do |dir|
11 dirs.each do |dir|
10 next if dir.blank?
12 next if dir.blank?
11 link_path << '/' unless link_path.empty?
13 link_path << '/' unless link_path.empty?
12 link_path << "#{dir}"
14 link_path << "#{dir}"
13 %>
15 %>
14 / <%= link_to h(dir), :action => 'show', :id => @project, :repository_id => @repository.identifier_param,
16 / <%= link_to h(dir), :action => 'show', :id => @project, :repository_id => @repository.identifier_param,
15 :path => to_path_param(link_path), :rev => @rev %>
17 :path => to_path_param(link_path), :rev => @rev %>
16 <% end %>
18 <% end %>
17 <% if filename %>
19 <% if filename %>
18 / <%= link_to h(filename),
20 / <%= link_to h(filename),
19 :action => 'changes', :id => @project, :repository_id => @repository.identifier_param,
21 :action => 'changes', :id => @project, :repository_id => @repository.identifier_param,
20 :path => to_path_param("#{link_path}/#{filename}"), :rev => @rev %>
22 :path => to_path_param("#{link_path}/#{filename}"), :rev => @rev %>
21 <% end %>
23 <% end %>
22 <%
24 <%
23 # @rev is revsion or Git and Mercurial branch or tag.
25 # @rev is revsion or Git and Mercurial branch or tag.
24 # For Mercurial *tip*, @rev and @changeset are nil.
26 # For Mercurial *tip*, @rev and @changeset are nil.
25 rev_text = @changeset.nil? ? @rev : format_revision(@changeset)
27 rev_text = @changeset.nil? ? @rev : format_revision(@changeset)
26 %>
28 %>
27 <%= "@ #{h rev_text}" unless rev_text.blank? %>
29 <%= "@ #{h rev_text}" unless rev_text.blank? %>
28
30
29 <% html_title(with_leading_slash(path)) -%>
31 <% html_title(with_leading_slash(path)) -%>
@@ -1,409 +1,412
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
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',
71 :attributes => {:href => '/projects/subproject1/repository'},
72 :content => 'root'
70 end
73 end
71
74
72 def test_show_non_default
75 def test_show_non_default
73 Repository::Subversion.create(:project => @project,
76 Repository::Subversion.create(:project => @project,
74 :url => self.class.subversion_repository_url,
77 :url => self.class.subversion_repository_url,
75 :is_default => false, :identifier => 'svn')
78 :is_default => false, :identifier => 'svn')
76
79
77 get :show, :id => PRJ_ID, :repository_id => 'svn'
80 get :show, :id => PRJ_ID, :repository_id => 'svn'
78 assert_response :success
81 assert_response :success
79 assert_template 'show'
82 assert_template 'show'
80 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]'
81 # Repository menu should link to the main repo
84 # Repository menu should link to the main repo
82 assert_select '#main-menu a[href=/projects/subproject1/repository]'
85 assert_select '#main-menu a[href=/projects/subproject1/repository]'
83 end
86 end
84
87
85 def test_browse_directory
88 def test_browse_directory
86 assert_equal 0, @repository.changesets.count
89 assert_equal 0, @repository.changesets.count
87 @repository.fetch_changesets
90 @repository.fetch_changesets
88 @project.reload
91 @project.reload
89 assert_equal NUM_REV, @repository.changesets.count
92 assert_equal NUM_REV, @repository.changesets.count
90 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]
91 assert_response :success
94 assert_response :success
92 assert_template 'show'
95 assert_template 'show'
93 assert_not_nil assigns(:entries)
96 assert_not_nil assigns(:entries)
94 assert_equal [
97 assert_equal [
95 '[folder_with_brackets]', 'folder', '.project',
98 '[folder_with_brackets]', 'folder', '.project',
96 'helloworld.c', 'textfile.txt'
99 'helloworld.c', 'textfile.txt'
97 ],
100 ],
98 assigns(:entries).collect(&:name)
101 assigns(:entries).collect(&:name)
99 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
102 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
100 assert_equal 'file', entry.kind
103 assert_equal 'file', entry.kind
101 assert_equal 'subversion_test/helloworld.c', entry.path
104 assert_equal 'subversion_test/helloworld.c', entry.path
102 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
105 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
103 end
106 end
104
107
105 def test_browse_at_given_revision
108 def test_browse_at_given_revision
106 assert_equal 0, @repository.changesets.count
109 assert_equal 0, @repository.changesets.count
107 @repository.fetch_changesets
110 @repository.fetch_changesets
108 @project.reload
111 @project.reload
109 assert_equal NUM_REV, @repository.changesets.count
112 assert_equal NUM_REV, @repository.changesets.count
110 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],
111 :rev => 4
114 :rev => 4
112 assert_response :success
115 assert_response :success
113 assert_template 'show'
116 assert_template 'show'
114 assert_not_nil assigns(:entries)
117 assert_not_nil assigns(:entries)
115 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'],
118 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'],
116 assigns(:entries).collect(&:name)
119 assigns(:entries).collect(&:name)
117 end
120 end
118
121
119 def test_file_changes
122 def test_file_changes
120 assert_equal 0, @repository.changesets.count
123 assert_equal 0, @repository.changesets.count
121 @repository.fetch_changesets
124 @repository.fetch_changesets
122 @project.reload
125 @project.reload
123 assert_equal NUM_REV, @repository.changesets.count
126 assert_equal NUM_REV, @repository.changesets.count
124 get :changes, :id => PRJ_ID,
127 get :changes, :id => PRJ_ID,
125 :path => repository_path_hash(['subversion_test', 'folder', 'helloworld.rb'])[:param]
128 :path => repository_path_hash(['subversion_test', 'folder', 'helloworld.rb'])[:param]
126 assert_response :success
129 assert_response :success
127 assert_template 'changes'
130 assert_template 'changes'
128
131
129 changesets = assigns(:changesets)
132 changesets = assigns(:changesets)
130 assert_not_nil changesets
133 assert_not_nil changesets
131 assert_equal %w(6 3 2), changesets.collect(&:revision)
134 assert_equal %w(6 3 2), changesets.collect(&:revision)
132
135
133 # svn properties displayed with svn >= 1.5 only
136 # svn properties displayed with svn >= 1.5 only
134 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
137 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
135 assert_not_nil assigns(:properties)
138 assert_not_nil assigns(:properties)
136 assert_equal 'native', assigns(:properties)['svn:eol-style']
139 assert_equal 'native', assigns(:properties)['svn:eol-style']
137 assert_tag :ul,
140 assert_tag :ul,
138 :child => { :tag => 'li',
141 :child => { :tag => 'li',
139 :child => { :tag => 'b', :content => 'svn:eol-style' },
142 :child => { :tag => 'b', :content => 'svn:eol-style' },
140 :child => { :tag => 'span', :content => 'native' } }
143 :child => { :tag => 'span', :content => 'native' } }
141 end
144 end
142 end
145 end
143
146
144 def test_directory_changes
147 def test_directory_changes
145 assert_equal 0, @repository.changesets.count
148 assert_equal 0, @repository.changesets.count
146 @repository.fetch_changesets
149 @repository.fetch_changesets
147 @project.reload
150 @project.reload
148 assert_equal NUM_REV, @repository.changesets.count
151 assert_equal NUM_REV, @repository.changesets.count
149 get :changes, :id => PRJ_ID,
152 get :changes, :id => PRJ_ID,
150 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
153 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
151 assert_response :success
154 assert_response :success
152 assert_template 'changes'
155 assert_template 'changes'
153
156
154 changesets = assigns(:changesets)
157 changesets = assigns(:changesets)
155 assert_not_nil changesets
158 assert_not_nil changesets
156 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)
157 end
160 end
158
161
159 def test_entry
162 def test_entry
160 assert_equal 0, @repository.changesets.count
163 assert_equal 0, @repository.changesets.count
161 @repository.fetch_changesets
164 @repository.fetch_changesets
162 @project.reload
165 @project.reload
163 assert_equal NUM_REV, @repository.changesets.count
166 assert_equal NUM_REV, @repository.changesets.count
164 get :entry, :id => PRJ_ID,
167 get :entry, :id => PRJ_ID,
165 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
168 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
166 assert_response :success
169 assert_response :success
167 assert_template 'entry'
170 assert_template 'entry'
168 end
171 end
169
172
170 def test_entry_should_send_if_too_big
173 def test_entry_should_send_if_too_big
171 assert_equal 0, @repository.changesets.count
174 assert_equal 0, @repository.changesets.count
172 @repository.fetch_changesets
175 @repository.fetch_changesets
173 @project.reload
176 @project.reload
174 assert_equal NUM_REV, @repository.changesets.count
177 assert_equal NUM_REV, @repository.changesets.count
175 # no files in the test repo is larger than 1KB...
178 # no files in the test repo is larger than 1KB...
176 with_settings :file_max_size_displayed => 0 do
179 with_settings :file_max_size_displayed => 0 do
177 get :entry, :id => PRJ_ID,
180 get :entry, :id => PRJ_ID,
178 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
181 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
179 assert_response :success
182 assert_response :success
180 assert_equal 'attachment; filename="helloworld.c"',
183 assert_equal 'attachment; filename="helloworld.c"',
181 @response.headers['Content-Disposition']
184 @response.headers['Content-Disposition']
182 end
185 end
183 end
186 end
184
187
185 def test_entry_at_given_revision
188 def test_entry_at_given_revision
186 assert_equal 0, @repository.changesets.count
189 assert_equal 0, @repository.changesets.count
187 @repository.fetch_changesets
190 @repository.fetch_changesets
188 @project.reload
191 @project.reload
189 assert_equal NUM_REV, @repository.changesets.count
192 assert_equal NUM_REV, @repository.changesets.count
190 get :entry, :id => PRJ_ID,
193 get :entry, :id => PRJ_ID,
191 :path => repository_path_hash(['subversion_test', 'helloworld.rb'])[:param],
194 :path => repository_path_hash(['subversion_test', 'helloworld.rb'])[:param],
192 :rev => 2
195 :rev => 2
193 assert_response :success
196 assert_response :success
194 assert_template 'entry'
197 assert_template 'entry'
195 # this line was removed in r3 and file was moved in r6
198 # this line was removed in r3 and file was moved in r6
196 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
199 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
197 :content => /Here's the code/
200 :content => /Here's the code/
198 end
201 end
199
202
200 def test_entry_not_found
203 def test_entry_not_found
201 assert_equal 0, @repository.changesets.count
204 assert_equal 0, @repository.changesets.count
202 @repository.fetch_changesets
205 @repository.fetch_changesets
203 @project.reload
206 @project.reload
204 assert_equal NUM_REV, @repository.changesets.count
207 assert_equal NUM_REV, @repository.changesets.count
205 get :entry, :id => PRJ_ID,
208 get :entry, :id => PRJ_ID,
206 :path => repository_path_hash(['subversion_test', 'zzz.c'])[:param]
209 :path => repository_path_hash(['subversion_test', 'zzz.c'])[:param]
207 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
210 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
208 :content => /The entry or revision was not found in the repository/
211 :content => /The entry or revision was not found in the repository/
209 end
212 end
210
213
211 def test_entry_download
214 def test_entry_download
212 assert_equal 0, @repository.changesets.count
215 assert_equal 0, @repository.changesets.count
213 @repository.fetch_changesets
216 @repository.fetch_changesets
214 @project.reload
217 @project.reload
215 assert_equal NUM_REV, @repository.changesets.count
218 assert_equal NUM_REV, @repository.changesets.count
216 get :entry, :id => PRJ_ID,
219 get :entry, :id => PRJ_ID,
217 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param],
220 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param],
218 :format => 'raw'
221 :format => 'raw'
219 assert_response :success
222 assert_response :success
220 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
223 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
221 end
224 end
222
225
223 def test_directory_entry
226 def test_directory_entry
224 assert_equal 0, @repository.changesets.count
227 assert_equal 0, @repository.changesets.count
225 @repository.fetch_changesets
228 @repository.fetch_changesets
226 @project.reload
229 @project.reload
227 assert_equal NUM_REV, @repository.changesets.count
230 assert_equal NUM_REV, @repository.changesets.count
228 get :entry, :id => PRJ_ID,
231 get :entry, :id => PRJ_ID,
229 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
232 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
230 assert_response :success
233 assert_response :success
231 assert_template 'show'
234 assert_template 'show'
232 assert_not_nil assigns(:entry)
235 assert_not_nil assigns(:entry)
233 assert_equal 'folder', assigns(:entry).name
236 assert_equal 'folder', assigns(:entry).name
234 end
237 end
235
238
236 # TODO: this test needs fixtures.
239 # TODO: this test needs fixtures.
237 def test_revision
240 def test_revision
238 get :revision, :id => 1, :rev => 2
241 get :revision, :id => 1, :rev => 2
239 assert_response :success
242 assert_response :success
240 assert_template 'revision'
243 assert_template 'revision'
241 assert_tag :tag => 'ul',
244 assert_tag :tag => 'ul',
242 :child => { :tag => 'li',
245 :child => { :tag => 'li',
243 # link to the entry at rev 2
246 # link to the entry at rev 2
244 :child => { :tag => 'a',
247 :child => { :tag => 'a',
245 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
248 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
246 :content => 'repo',
249 :content => 'repo',
247 # link to partial diff
250 # link to partial diff
248 :sibling => { :tag => 'a',
251 :sibling => { :tag => 'a',
249 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
252 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
250 }
253 }
251 }
254 }
252 }
255 }
253 end
256 end
254
257
255 def test_invalid_revision
258 def test_invalid_revision
256 assert_equal 0, @repository.changesets.count
259 assert_equal 0, @repository.changesets.count
257 @repository.fetch_changesets
260 @repository.fetch_changesets
258 @project.reload
261 @project.reload
259 assert_equal NUM_REV, @repository.changesets.count
262 assert_equal NUM_REV, @repository.changesets.count
260 get :revision, :id => PRJ_ID, :rev => 'something_weird'
263 get :revision, :id => PRJ_ID, :rev => 'something_weird'
261 assert_response 404
264 assert_response 404
262 assert_error_tag :content => /was not found/
265 assert_error_tag :content => /was not found/
263 end
266 end
264
267
265 def test_invalid_revision_diff
268 def test_invalid_revision_diff
266 get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird'
269 get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird'
267 assert_response 404
270 assert_response 404
268 assert_error_tag :content => /was not found/
271 assert_error_tag :content => /was not found/
269 end
272 end
270
273
271 def test_empty_revision
274 def test_empty_revision
272 assert_equal 0, @repository.changesets.count
275 assert_equal 0, @repository.changesets.count
273 @repository.fetch_changesets
276 @repository.fetch_changesets
274 @project.reload
277 @project.reload
275 assert_equal NUM_REV, @repository.changesets.count
278 assert_equal NUM_REV, @repository.changesets.count
276 ['', ' ', nil].each do |r|
279 ['', ' ', nil].each do |r|
277 get :revision, :id => PRJ_ID, :rev => r
280 get :revision, :id => PRJ_ID, :rev => r
278 assert_response 404
281 assert_response 404
279 assert_error_tag :content => /was not found/
282 assert_error_tag :content => /was not found/
280 end
283 end
281 end
284 end
282
285
283 # TODO: this test needs fixtures.
286 # TODO: this test needs fixtures.
284 def test_revision_with_repository_pointing_to_a_subdirectory
287 def test_revision_with_repository_pointing_to_a_subdirectory
285 r = Project.find(1).repository
288 r = Project.find(1).repository
286 # Changes repository url to a subdirectory
289 # Changes repository url to a subdirectory
287 r.update_attribute :url, (r.url + '/test/some')
290 r.update_attribute :url, (r.url + '/test/some')
288
291
289 get :revision, :id => 1, :rev => 2
292 get :revision, :id => 1, :rev => 2
290 assert_response :success
293 assert_response :success
291 assert_template 'revision'
294 assert_template 'revision'
292 assert_tag :tag => 'ul',
295 assert_tag :tag => 'ul',
293 :child => { :tag => 'li',
296 :child => { :tag => 'li',
294 # link to the entry at rev 2
297 # link to the entry at rev 2
295 :child => { :tag => 'a',
298 :child => { :tag => 'a',
296 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
299 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
297 :content => 'repo',
300 :content => 'repo',
298 # link to partial diff
301 # link to partial diff
299 :sibling => { :tag => 'a',
302 :sibling => { :tag => 'a',
300 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
303 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
301 }
304 }
302 }
305 }
303 }
306 }
304 end
307 end
305
308
306 def test_revision_diff
309 def test_revision_diff
307 assert_equal 0, @repository.changesets.count
310 assert_equal 0, @repository.changesets.count
308 @repository.fetch_changesets
311 @repository.fetch_changesets
309 @project.reload
312 @project.reload
310 assert_equal NUM_REV, @repository.changesets.count
313 assert_equal NUM_REV, @repository.changesets.count
311 ['inline', 'sbs'].each do |dt|
314 ['inline', 'sbs'].each do |dt|
312 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
315 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
313 assert_response :success
316 assert_response :success
314 assert_template 'diff'
317 assert_template 'diff'
315 assert_tag :tag => 'h2',
318 assert_tag :tag => 'h2',
316 :content => / 3/
319 :content => / 3/
317 end
320 end
318 end
321 end
319
322
320 def test_revision_diff_raw_format
323 def test_revision_diff_raw_format
321 assert_equal 0, @repository.changesets.count
324 assert_equal 0, @repository.changesets.count
322 @repository.fetch_changesets
325 @repository.fetch_changesets
323 @project.reload
326 @project.reload
324 assert_equal NUM_REV, @repository.changesets.count
327 assert_equal NUM_REV, @repository.changesets.count
325
328
326 get :diff, :id => PRJ_ID, :rev => 3, :format => 'diff'
329 get :diff, :id => PRJ_ID, :rev => 3, :format => 'diff'
327 assert_response :success
330 assert_response :success
328 assert_equal 'text/x-patch', @response.content_type
331 assert_equal 'text/x-patch', @response.content_type
329 assert_equal 'Index: subversion_test/textfile.txt', @response.body.split(/\r?\n/).first
332 assert_equal 'Index: subversion_test/textfile.txt', @response.body.split(/\r?\n/).first
330 end
333 end
331
334
332 def test_directory_diff
335 def test_directory_diff
333 assert_equal 0, @repository.changesets.count
336 assert_equal 0, @repository.changesets.count
334 @repository.fetch_changesets
337 @repository.fetch_changesets
335 @project.reload
338 @project.reload
336 assert_equal NUM_REV, @repository.changesets.count
339 assert_equal NUM_REV, @repository.changesets.count
337 ['inline', 'sbs'].each do |dt|
340 ['inline', 'sbs'].each do |dt|
338 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2,
341 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2,
339 :path => repository_path_hash(['subversion_test', 'folder'])[:param],
342 :path => repository_path_hash(['subversion_test', 'folder'])[:param],
340 :type => dt
343 :type => dt
341 assert_response :success
344 assert_response :success
342 assert_template 'diff'
345 assert_template 'diff'
343
346
344 diff = assigns(:diff)
347 diff = assigns(:diff)
345 assert_not_nil diff
348 assert_not_nil diff
346 # 2 files modified
349 # 2 files modified
347 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
350 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
348 assert_tag :tag => 'h2', :content => /2:6/
351 assert_tag :tag => 'h2', :content => /2:6/
349 end
352 end
350 end
353 end
351
354
352 def test_annotate
355 def test_annotate
353 assert_equal 0, @repository.changesets.count
356 assert_equal 0, @repository.changesets.count
354 @repository.fetch_changesets
357 @repository.fetch_changesets
355 @project.reload
358 @project.reload
356 assert_equal NUM_REV, @repository.changesets.count
359 assert_equal NUM_REV, @repository.changesets.count
357 get :annotate, :id => PRJ_ID,
360 get :annotate, :id => PRJ_ID,
358 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
361 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
359 assert_response :success
362 assert_response :success
360 assert_template 'annotate'
363 assert_template 'annotate'
361 end
364 end
362
365
363 def test_annotate_at_given_revision
366 def test_annotate_at_given_revision
364 assert_equal 0, @repository.changesets.count
367 assert_equal 0, @repository.changesets.count
365 @repository.fetch_changesets
368 @repository.fetch_changesets
366 @project.reload
369 @project.reload
367 assert_equal NUM_REV, @repository.changesets.count
370 assert_equal NUM_REV, @repository.changesets.count
368 get :annotate, :id => PRJ_ID, :rev => 8,
371 get :annotate, :id => PRJ_ID, :rev => 8,
369 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
372 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
370 assert_response :success
373 assert_response :success
371 assert_template 'annotate'
374 assert_template 'annotate'
372 assert_tag :tag => 'h2', :content => /@ 8/
375 assert_tag :tag => 'h2', :content => /@ 8/
373 end
376 end
374
377
375 def test_destroy_valid_repository
378 def test_destroy_valid_repository
376 @request.session[:user_id] = 1 # admin
379 @request.session[:user_id] = 1 # admin
377 assert_equal 0, @repository.changesets.count
380 assert_equal 0, @repository.changesets.count
378 @repository.fetch_changesets
381 @repository.fetch_changesets
379 assert_equal NUM_REV, @repository.changesets.count
382 assert_equal NUM_REV, @repository.changesets.count
380
383
381 assert_difference 'Repository.count', -1 do
384 assert_difference 'Repository.count', -1 do
382 delete :destroy, :id => @repository.id
385 delete :destroy, :id => @repository.id
383 end
386 end
384 assert_response 302
387 assert_response 302
385 @project.reload
388 @project.reload
386 assert_nil @project.repository
389 assert_nil @project.repository
387 end
390 end
388
391
389 def test_destroy_invalid_repository
392 def test_destroy_invalid_repository
390 @request.session[:user_id] = 1 # admin
393 @request.session[:user_id] = 1 # admin
391 @project.repository.destroy
394 @project.repository.destroy
392 @repository = Repository::Subversion.create!(
395 @repository = Repository::Subversion.create!(
393 :project => @project,
396 :project => @project,
394 :url => "file:///invalid")
397 :url => "file:///invalid")
395 @repository.fetch_changesets
398 @repository.fetch_changesets
396 assert_equal 0, @repository.changesets.count
399 assert_equal 0, @repository.changesets.count
397
400
398 assert_difference 'Repository.count', -1 do
401 assert_difference 'Repository.count', -1 do
399 delete :destroy, :id => @repository.id
402 delete :destroy, :id => @repository.id
400 end
403 end
401 assert_response 302
404 assert_response 302
402 @project.reload
405 @project.reload
403 assert_nil @project.repository
406 assert_nil @project.repository
404 end
407 end
405 else
408 else
406 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
409 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
407 def test_fake; assert true end
410 def test_fake; assert true end
408 end
411 end
409 end
412 end
General Comments 0
You need to be logged in to leave comments. Login now