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