@@ -1,260 +1,261 | |||||
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 RepositoriesCvsControllerTest < ActionController::TestCase |
|
24 | class RepositoriesCvsControllerTest < ActionController::TestCase | |
25 | fixtures :projects, :users, :roles, :members, :member_roles, |
|
25 | fixtures :projects, :users, :roles, :members, :member_roles, | |
26 | :repositories, :enabled_modules |
|
26 | :repositories, :enabled_modules | |
27 |
|
27 | |||
28 | REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s |
|
28 | REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s | |
29 | REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? |
|
29 | REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? | |
30 | # CVS module |
|
30 | # CVS module | |
31 | MODULE_NAME = 'test' |
|
31 | MODULE_NAME = 'test' | |
32 | PRJ_ID = 3 |
|
32 | PRJ_ID = 3 | |
33 | NUM_REV = 7 |
|
33 | NUM_REV = 7 | |
34 |
|
34 | |||
35 | def setup |
|
35 | def setup | |
36 | @controller = RepositoriesController.new |
|
36 | @controller = RepositoriesController.new | |
37 | @request = ActionController::TestRequest.new |
|
37 | @request = ActionController::TestRequest.new | |
38 | @response = ActionController::TestResponse.new |
|
38 | @response = ActionController::TestResponse.new | |
39 | Setting.default_language = 'en' |
|
39 | Setting.default_language = 'en' | |
40 | User.current = nil |
|
40 | User.current = nil | |
41 |
|
41 | |||
42 | @project = Project.find(PRJ_ID) |
|
42 | @project = Project.find(PRJ_ID) | |
43 | @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID), |
|
43 | @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID), | |
44 | :root_url => REPOSITORY_PATH, |
|
44 | :root_url => REPOSITORY_PATH, | |
45 | :url => MODULE_NAME, |
|
45 | :url => MODULE_NAME, | |
46 | :log_encoding => 'UTF-8') |
|
46 | :log_encoding => 'UTF-8') | |
47 | assert @repository |
|
47 | assert @repository | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | if File.directory?(REPOSITORY_PATH) |
|
50 | if File.directory?(REPOSITORY_PATH) | |
51 | def test_browse_root |
|
51 | def test_browse_root | |
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_equal 3, assigns(:entries).size |
|
60 | assert_equal 3, assigns(:entries).size | |
61 |
|
61 | |||
62 | entry = assigns(:entries).detect {|e| e.name == 'images'} |
|
62 | entry = assigns(:entries).detect {|e| e.name == 'images'} | |
63 | assert_equal 'dir', entry.kind |
|
63 | assert_equal 'dir', entry.kind | |
64 |
|
64 | |||
65 | entry = assigns(:entries).detect {|e| e.name == 'README'} |
|
65 | entry = assigns(:entries).detect {|e| e.name == 'README'} | |
66 | assert_equal 'file', entry.kind |
|
66 | assert_equal 'file', entry.kind | |
67 |
|
67 | |||
68 | assert_not_nil assigns(:changesets) |
|
68 | assert_not_nil assigns(:changesets) | |
69 | assert assigns(:changesets).size > 0 |
|
69 | assert assigns(:changesets).size > 0 | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def test_browse_directory |
|
72 | def test_browse_directory | |
73 | @repository.fetch_changesets |
|
73 | @repository.fetch_changesets | |
74 | @repository.reload |
|
74 | @repository.reload | |
75 | get :show, :id => PRJ_ID, :path => ['images'] |
|
75 | get :show, :id => PRJ_ID, :path => ['images'] | |
76 | assert_response :success |
|
76 | assert_response :success | |
77 | assert_template 'show' |
|
77 | assert_template 'show' | |
78 | assert_not_nil assigns(:entries) |
|
78 | assert_not_nil assigns(:entries) | |
79 | assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
79 | assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
80 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
80 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
81 | assert_not_nil entry |
|
81 | assert_not_nil entry | |
82 | assert_equal 'file', entry.kind |
|
82 | assert_equal 'file', entry.kind | |
83 | assert_equal 'images/edit.png', entry.path |
|
83 | assert_equal 'images/edit.png', entry.path | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | def test_browse_at_given_revision |
|
86 | def test_browse_at_given_revision | |
87 | @repository.fetch_changesets |
|
87 | @repository.fetch_changesets | |
88 | @repository.reload |
|
88 | @repository.reload | |
89 | get :show, :id => PRJ_ID, :path => ['images'], :rev => 1 |
|
89 | get :show, :id => PRJ_ID, :path => ['images'], :rev => 1 | |
90 | assert_response :success |
|
90 | assert_response :success | |
91 | assert_template 'show' |
|
91 | assert_template 'show' | |
92 | assert_not_nil assigns(:entries) |
|
92 | assert_not_nil assigns(:entries) | |
93 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
93 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
94 | end |
|
94 | end | |
95 |
|
95 | |||
96 | def test_entry |
|
96 | def test_entry | |
97 | @repository.fetch_changesets |
|
97 | @repository.fetch_changesets | |
98 | @repository.reload |
|
98 | @repository.reload | |
99 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
|
99 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] | |
100 | assert_response :success |
|
100 | assert_response :success | |
101 | assert_template 'entry' |
|
101 | assert_template 'entry' | |
102 | assert_no_tag :tag => 'td', |
|
102 | assert_no_tag :tag => 'td', | |
103 | :attributes => { :class => /line-code/}, |
|
103 | :attributes => { :class => /line-code/}, | |
104 | :content => /before_filter/ |
|
104 | :content => /before_filter/ | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def test_entry_at_given_revision |
|
107 | def test_entry_at_given_revision | |
108 | # changesets must be loaded |
|
108 | # changesets must be loaded | |
109 | @repository.fetch_changesets |
|
109 | @repository.fetch_changesets | |
110 | @repository.reload |
|
110 | @repository.reload | |
111 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 2 |
|
111 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 2 | |
112 | assert_response :success |
|
112 | assert_response :success | |
113 | assert_template 'entry' |
|
113 | assert_template 'entry' | |
114 | # this line was removed in r3 |
|
114 | # this line was removed in r3 | |
115 | assert_tag :tag => 'td', |
|
115 | assert_tag :tag => 'td', | |
116 | :attributes => { :class => /line-code/}, |
|
116 | :attributes => { :class => /line-code/}, | |
117 | :content => /before_filter/ |
|
117 | :content => /before_filter/ | |
118 | end |
|
118 | end | |
119 |
|
119 | |||
120 | def test_entry_not_found |
|
120 | def test_entry_not_found | |
121 | @repository.fetch_changesets |
|
121 | @repository.fetch_changesets | |
122 | @repository.reload |
|
122 | @repository.reload | |
123 | get :entry, :id => PRJ_ID, :path => ['sources', 'zzz.c'] |
|
123 | get :entry, :id => PRJ_ID, :path => ['sources', 'zzz.c'] | |
124 | assert_tag :tag => 'p', |
|
124 | assert_tag :tag => 'p', | |
125 | :attributes => { :id => /errorExplanation/ }, |
|
125 | :attributes => { :id => /errorExplanation/ }, | |
126 | :content => /The entry or revision was not found in the repository/ |
|
126 | :content => /The entry or revision was not found in the repository/ | |
127 | end |
|
127 | end | |
128 |
|
128 | |||
129 | def test_entry_download |
|
129 | def test_entry_download | |
130 | @repository.fetch_changesets |
|
130 | @repository.fetch_changesets | |
131 | @repository.reload |
|
131 | @repository.reload | |
132 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], |
|
132 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], | |
133 | :format => 'raw' |
|
133 | :format => 'raw' | |
134 | assert_response :success |
|
134 | assert_response :success | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | def test_directory_entry |
|
137 | def test_directory_entry | |
138 | @repository.fetch_changesets |
|
138 | @repository.fetch_changesets | |
139 | @repository.reload |
|
139 | @repository.reload | |
140 | get :entry, :id => PRJ_ID, :path => ['sources'] |
|
140 | get :entry, :id => PRJ_ID, :path => ['sources'] | |
141 | assert_response :success |
|
141 | assert_response :success | |
142 | assert_template 'show' |
|
142 | assert_template 'show' | |
143 | assert_not_nil assigns(:entry) |
|
143 | assert_not_nil assigns(:entry) | |
144 | assert_equal 'sources', assigns(:entry).name |
|
144 | assert_equal 'sources', assigns(:entry).name | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | def test_diff |
|
147 | def test_diff | |
148 | @repository.fetch_changesets |
|
148 | @repository.fetch_changesets | |
149 | @repository.reload |
|
149 | @repository.reload | |
150 | ['inline', 'sbs'].each do |dt| |
|
150 | ['inline', 'sbs'].each do |dt| | |
151 | get :diff, :id => PRJ_ID, :rev => 3, :type => dt |
|
151 | get :diff, :id => PRJ_ID, :rev => 3, :type => dt | |
152 | assert_response :success |
|
152 | assert_response :success | |
153 | assert_template 'diff' |
|
153 | assert_template 'diff' | |
154 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' }, |
|
154 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' }, | |
155 | :content => /before_filter :require_login/ |
|
155 | :content => /before_filter :require_login/ | |
156 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, |
|
156 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, | |
157 | :content => /with one change/ |
|
157 | :content => /with one change/ | |
158 | end |
|
158 | end | |
159 | end |
|
159 | end | |
160 |
|
160 | |||
161 | def test_diff_new_files |
|
161 | def test_diff_new_files | |
162 | @repository.fetch_changesets |
|
162 | @repository.fetch_changesets | |
163 | @repository.reload |
|
163 | @repository.reload | |
164 | ['inline', 'sbs'].each do |dt| |
|
164 | ['inline', 'sbs'].each do |dt| | |
165 | get :diff, :id => PRJ_ID, :rev => 1, :type => dt |
|
165 | get :diff, :id => PRJ_ID, :rev => 1, :type => dt | |
166 | assert_response :success |
|
166 | assert_response :success | |
167 | assert_template 'diff' |
|
167 | assert_template 'diff' | |
168 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, |
|
168 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, | |
169 | :content => /watched.remove_watcher/ |
|
169 | :content => /watched.remove_watcher/ | |
170 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, |
|
170 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, | |
171 | :content => /test\/README/ |
|
171 | :content => /test\/README/ | |
172 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, |
|
172 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, | |
173 | :content => /test\/images\/delete.png / |
|
173 | :content => /test\/images\/delete.png / | |
174 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, |
|
174 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, | |
175 | :content => /test\/images\/edit.png/ |
|
175 | :content => /test\/images\/edit.png/ | |
176 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, |
|
176 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, | |
177 | :content => /test\/sources\/watchers_controller.rb/ |
|
177 | :content => /test\/sources\/watchers_controller.rb/ | |
178 | end |
|
178 | end | |
179 | end |
|
179 | end | |
180 |
|
180 | |||
181 | def test_annotate |
|
181 | def test_annotate | |
182 | @repository.fetch_changesets |
|
182 | @repository.fetch_changesets | |
183 | @repository.reload |
|
183 | @repository.reload | |
184 | get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
|
184 | get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] | |
185 | assert_response :success |
|
185 | assert_response :success | |
186 | assert_template 'annotate' |
|
186 | assert_template 'annotate' | |
187 | # 1.1 line |
|
187 | # 1.1 line | |
188 | assert_tag :tag => 'th', |
|
188 | assert_tag :tag => 'th', | |
189 | :attributes => { :class => 'line-num' }, |
|
189 | :attributes => { :class => 'line-num' }, | |
190 | :content => '18', |
|
190 | :content => '18', | |
191 | :sibling => { |
|
191 | :sibling => { | |
192 | :tag => 'td', |
|
192 | :tag => 'td', | |
193 | :attributes => { :class => 'revision' }, |
|
193 | :attributes => { :class => 'revision' }, | |
194 | :content => /1.1/, |
|
194 | :content => /1.1/, | |
195 | :sibling => { |
|
195 | :sibling => { | |
196 | :tag => 'td', |
|
196 | :tag => 'td', | |
197 | :attributes => { :class => 'author' }, |
|
197 | :attributes => { :class => 'author' }, | |
198 | :content => /LANG/ |
|
198 | :content => /LANG/ | |
199 | } |
|
199 | } | |
200 | } |
|
200 | } | |
201 | # 1.2 line |
|
201 | # 1.2 line | |
202 | assert_tag :tag => 'th', |
|
202 | assert_tag :tag => 'th', | |
203 | :attributes => { :class => 'line-num' }, |
|
203 | :attributes => { :class => 'line-num' }, | |
204 | :content => '32', |
|
204 | :content => '32', | |
205 | :sibling => { |
|
205 | :sibling => { | |
206 | :tag => 'td', |
|
206 | :tag => 'td', | |
207 | :attributes => { :class => 'revision' }, |
|
207 | :attributes => { :class => 'revision' }, | |
208 | :content => /1.2/, |
|
208 | :content => /1.2/, | |
209 | :sibling => { |
|
209 | :sibling => { | |
210 | :tag => 'td', |
|
210 | :tag => 'td', | |
211 | :attributes => { :class => 'author' }, |
|
211 | :attributes => { :class => 'author' }, | |
212 | :content => /LANG/ |
|
212 | :content => /LANG/ | |
213 | } |
|
213 | } | |
214 | } |
|
214 | } | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | def test_destroy_valid_repository |
|
217 | def test_destroy_valid_repository | |
218 | @request.session[:user_id] = 1 # admin |
|
218 | @request.session[:user_id] = 1 # admin | |
|
219 | assert_equal 0, @repository.changesets.count | |||
219 | @repository.fetch_changesets |
|
220 | @repository.fetch_changesets | |
220 |
@ |
|
221 | @project.reload | |
221 |
assert @repository.changesets.count |
|
222 | assert_equal NUM_REV, @repository.changesets.count | |
222 |
|
223 | |||
223 | get :destroy, :id => PRJ_ID |
|
224 | get :destroy, :id => PRJ_ID | |
224 | assert_response 302 |
|
225 | assert_response 302 | |
225 | @project.reload |
|
226 | @project.reload | |
226 | assert_nil @project.repository |
|
227 | assert_nil @project.repository | |
227 | end |
|
228 | end | |
228 |
|
229 | |||
229 | def test_destroy_invalid_repository |
|
230 | def test_destroy_invalid_repository | |
230 | @request.session[:user_id] = 1 # admin |
|
231 | @request.session[:user_id] = 1 # admin | |
231 | @repository.fetch_changesets |
|
232 | @repository.fetch_changesets | |
232 | @repository.reload |
|
233 | @repository.reload | |
233 | assert @repository.changesets.count > 0 |
|
234 | assert @repository.changesets.count > 0 | |
234 |
|
235 | |||
235 | get :destroy, :id => PRJ_ID |
|
236 | get :destroy, :id => PRJ_ID | |
236 | assert_response 302 |
|
237 | assert_response 302 | |
237 | @project.reload |
|
238 | @project.reload | |
238 | assert_nil @project.repository |
|
239 | assert_nil @project.repository | |
239 |
|
240 | |||
240 | @repository = Repository::Cvs.create( |
|
241 | @repository = Repository::Cvs.create( | |
241 | :project => Project.find(PRJ_ID), |
|
242 | :project => Project.find(PRJ_ID), | |
242 | :root_url => "/invalid", |
|
243 | :root_url => "/invalid", | |
243 | :url => MODULE_NAME, |
|
244 | :url => MODULE_NAME, | |
244 | :log_encoding => 'UTF-8' |
|
245 | :log_encoding => 'UTF-8' | |
245 | ) |
|
246 | ) | |
246 | assert @repository |
|
247 | assert @repository | |
247 | @repository.fetch_changesets |
|
248 | @repository.fetch_changesets | |
248 | @repository.reload |
|
249 | @repository.reload | |
249 | assert_equal 0, @repository.changesets.count |
|
250 | assert_equal 0, @repository.changesets.count | |
250 |
|
251 | |||
251 | get :destroy, :id => PRJ_ID |
|
252 | get :destroy, :id => PRJ_ID | |
252 | assert_response 302 |
|
253 | assert_response 302 | |
253 | @project.reload |
|
254 | @project.reload | |
254 | assert_nil @project.repository |
|
255 | assert_nil @project.repository | |
255 | end |
|
256 | end | |
256 | else |
|
257 | else | |
257 | puts "CVS test repository NOT FOUND. Skipping functional tests !!!" |
|
258 | puts "CVS test repository NOT FOUND. Skipping functional tests !!!" | |
258 | def test_fake; assert true end |
|
259 | def test_fake; assert true end | |
259 | end |
|
260 | end | |
260 | end |
|
261 | end |
General Comments 0
You need to be logged in to leave comments.
Login now