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