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