##// 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 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoriesCvsControllerTest < ActionController::TestCase
21 21 tests RepositoriesController
22 22
23 23 fixtures :projects, :users, :roles, :members, :member_roles,
24 24 :repositories, :enabled_modules
25 25
26 26 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
27 27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 28 # CVS module
29 29 MODULE_NAME = 'test'
30 30 PRJ_ID = 3
31 31 NUM_REV = 7
32 32
33 33 def setup
34 34 Setting.default_language = 'en'
35 35 User.current = nil
36 36
37 37 @project = Project.find(PRJ_ID)
38 38 @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
39 39 :root_url => REPOSITORY_PATH,
40 40 :url => MODULE_NAME,
41 41 :log_encoding => 'UTF-8')
42 42 assert @repository
43 43 end
44 44
45 45 if File.directory?(REPOSITORY_PATH)
46 46 def test_get_new
47 47 @request.session[:user_id] = 1
48 48 @project.repository.destroy
49 49 get :new, :project_id => 'subproject1', :repository_scm => 'Cvs'
50 50 assert_response :success
51 51 assert_template 'new'
52 52 assert_kind_of Repository::Cvs, assigns(:repository)
53 53 assert assigns(:repository).new_record?
54 54 end
55 55
56 56 def test_browse_root
57 57 assert_equal 0, @repository.changesets.count
58 58 @repository.fetch_changesets
59 59 @project.reload
60 60 assert_equal NUM_REV, @repository.changesets.count
61 61 get :show, :id => PRJ_ID
62 62 assert_response :success
63 63 assert_template 'show'
64 64 assert_not_nil assigns(:entries)
65 65 assert_equal 3, assigns(:entries).size
66 66
67 67 entry = assigns(:entries).detect {|e| e.name == 'images'}
68 68 assert_equal 'dir', entry.kind
69 69
70 70 entry = assigns(:entries).detect {|e| e.name == 'README'}
71 71 assert_equal 'file', entry.kind
72 72
73 73 assert_not_nil assigns(:changesets)
74 74 assert assigns(:changesets).size > 0
75 75 end
76 76
77 77 def test_browse_directory
78 78 assert_equal 0, @repository.changesets.count
79 79 @repository.fetch_changesets
80 80 @project.reload
81 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 83 assert_response :success
84 84 assert_template 'show'
85 85 assert_not_nil assigns(:entries)
86 86 assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
87 87 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
88 88 assert_not_nil entry
89 89 assert_equal 'file', entry.kind
90 90 assert_equal 'images/edit.png', entry.path
91 91 end
92 92
93 93 def test_browse_at_given_revision
94 94 assert_equal 0, @repository.changesets.count
95 95 @repository.fetch_changesets
96 96 @project.reload
97 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 100 assert_response :success
100 101 assert_template 'show'
101 102 assert_not_nil assigns(:entries)
102 103 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
103 104 end
104 105
105 106 def test_entry
106 107 assert_equal 0, @repository.changesets.count
107 108 @repository.fetch_changesets
108 109 @project.reload
109 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 113 assert_response :success
112 114 assert_template 'entry'
113 115 assert_no_tag :tag => 'td',
114 116 :attributes => { :class => /line-code/},
115 117 :content => /before_filter/
116 118 end
117 119
118 120 def test_entry_at_given_revision
119 121 # changesets must be loaded
120 122 assert_equal 0, @repository.changesets.count
121 123 @repository.fetch_changesets
122 124 @project.reload
123 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 129 assert_response :success
126 130 assert_template 'entry'
127 131 # this line was removed in r3
128 132 assert_tag :tag => 'td',
129 133 :attributes => { :class => /line-code/},
130 134 :content => /before_filter/
131 135 end
132 136
133 137 def test_entry_not_found
134 138 assert_equal 0, @repository.changesets.count
135 139 @repository.fetch_changesets
136 140 @project.reload
137 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 144 assert_tag :tag => 'p',
140 145 :attributes => { :id => /errorExplanation/ },
141 146 :content => /The entry or revision was not found in the repository/
142 147 end
143 148
144 149 def test_entry_download
145 150 assert_equal 0, @repository.changesets.count
146 151 @repository.fetch_changesets
147 152 @project.reload
148 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 156 :format => 'raw'
151 157 assert_response :success
152 158 end
153 159
154 160 def test_directory_entry
155 161 assert_equal 0, @repository.changesets.count
156 162 @repository.fetch_changesets
157 163 @project.reload
158 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 167 assert_response :success
161 168 assert_template 'show'
162 169 assert_not_nil assigns(:entry)
163 170 assert_equal 'sources', assigns(:entry).name
164 171 end
165 172
166 173 def test_diff
167 174 assert_equal 0, @repository.changesets.count
168 175 @repository.fetch_changesets
169 176 @project.reload
170 177 assert_equal NUM_REV, @repository.changesets.count
171 178 ['inline', 'sbs'].each do |dt|
172 179 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
173 180 assert_response :success
174 181 assert_template 'diff'
175 182 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
176 183 :content => /before_filter :require_login/
177 184 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
178 185 :content => /with one change/
179 186 end
180 187 end
181 188
182 189 def test_diff_new_files
183 190 assert_equal 0, @repository.changesets.count
184 191 @repository.fetch_changesets
185 192 @project.reload
186 193 assert_equal NUM_REV, @repository.changesets.count
187 194 ['inline', 'sbs'].each do |dt|
188 195 get :diff, :id => PRJ_ID, :rev => 1, :type => dt
189 196 assert_response :success
190 197 assert_template 'diff'
191 198 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
192 199 :content => /watched.remove_watcher/
193 200 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
194 201 :content => /test\/README/
195 202 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
196 203 :content => /test\/images\/delete.png /
197 204 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
198 205 :content => /test\/images\/edit.png/
199 206 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
200 207 :content => /test\/sources\/watchers_controller.rb/
201 208 end
202 209 end
203 210
204 211 def test_annotate
205 212 assert_equal 0, @repository.changesets.count
206 213 @repository.fetch_changesets
207 214 @project.reload
208 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 218 assert_response :success
211 219 assert_template 'annotate'
212 220 # 1.1 line
213 221 assert_tag :tag => 'th',
214 222 :attributes => { :class => 'line-num' },
215 223 :content => '18',
216 224 :sibling => {
217 225 :tag => 'td',
218 226 :attributes => { :class => 'revision' },
219 227 :content => /1.1/,
220 228 :sibling => {
221 229 :tag => 'td',
222 230 :attributes => { :class => 'author' },
223 231 :content => /LANG/
224 232 }
225 233 }
226 234 # 1.2 line
227 235 assert_tag :tag => 'th',
228 236 :attributes => { :class => 'line-num' },
229 237 :content => '32',
230 238 :sibling => {
231 239 :tag => 'td',
232 240 :attributes => { :class => 'revision' },
233 241 :content => /1.2/,
234 242 :sibling => {
235 243 :tag => 'td',
236 244 :attributes => { :class => 'author' },
237 245 :content => /LANG/
238 246 }
239 247 }
240 248 end
241 249
242 250 def test_destroy_valid_repository
243 251 @request.session[:user_id] = 1 # admin
244 252 assert_equal 0, @repository.changesets.count
245 253 @repository.fetch_changesets
246 254 @project.reload
247 255 assert_equal NUM_REV, @repository.changesets.count
248 256
249 257 assert_difference 'Repository.count', -1 do
250 258 delete :destroy, :id => @repository.id
251 259 end
252 260 assert_response 302
253 261 @project.reload
254 262 assert_nil @project.repository
255 263 end
256 264
257 265 def test_destroy_invalid_repository
258 266 @request.session[:user_id] = 1 # admin
259 267 @project.repository.destroy
260 268 @repository = Repository::Cvs.create!(
261 269 :project => Project.find(PRJ_ID),
262 270 :root_url => "/invalid",
263 271 :url => MODULE_NAME,
264 272 :log_encoding => 'UTF-8'
265 273 )
266 274 @repository.fetch_changesets
267 275 @project.reload
268 276 assert_equal 0, @repository.changesets.count
269 277
270 278 assert_difference 'Repository.count', -1 do
271 279 delete :destroy, :id => @repository.id
272 280 end
273 281 assert_response 302
274 282 @project.reload
275 283 assert_nil @project.repository
276 284 end
277 285 else
278 286 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
279 287 def test_fake; assert true end
280 288 end
281 289 end
General Comments 0
You need to be logged in to leave comments. Login now