##// END OF EJS Templates
Rails3: scm: cvs: fix error of test_entry at functional test...
Toshi MARUYAMA -
r7058:9028ea4d7bbf
parent child
Show More
@@ -1,270 +1,272
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 assert_equal 0, @repository.changesets.count
101 102 @repository.fetch_changesets
102 @repository.reload
103 @project.reload
104 assert_equal NUM_REV, @repository.changesets.count
103 105 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
104 106 assert_response :success
105 107 assert_template 'entry'
106 108 assert_no_tag :tag => 'td',
107 109 :attributes => { :class => /line-code/},
108 110 :content => /before_filter/
109 111 end
110 112
111 113 def test_entry_at_given_revision
112 114 # changesets must be loaded
113 115 @repository.fetch_changesets
114 116 @repository.reload
115 117 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 2
116 118 assert_response :success
117 119 assert_template 'entry'
118 120 # this line was removed in r3
119 121 assert_tag :tag => 'td',
120 122 :attributes => { :class => /line-code/},
121 123 :content => /before_filter/
122 124 end
123 125
124 126 def test_entry_not_found
125 127 @repository.fetch_changesets
126 128 @repository.reload
127 129 get :entry, :id => PRJ_ID, :path => ['sources', 'zzz.c']
128 130 assert_tag :tag => 'p',
129 131 :attributes => { :id => /errorExplanation/ },
130 132 :content => /The entry or revision was not found in the repository/
131 133 end
132 134
133 135 def test_entry_download
134 136 @repository.fetch_changesets
135 137 @repository.reload
136 138 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
137 139 :format => 'raw'
138 140 assert_response :success
139 141 end
140 142
141 143 def test_directory_entry
142 144 @repository.fetch_changesets
143 145 @repository.reload
144 146 get :entry, :id => PRJ_ID, :path => ['sources']
145 147 assert_response :success
146 148 assert_template 'show'
147 149 assert_not_nil assigns(:entry)
148 150 assert_equal 'sources', assigns(:entry).name
149 151 end
150 152
151 153 def test_diff
152 154 @repository.fetch_changesets
153 155 @repository.reload
154 156 ['inline', 'sbs'].each do |dt|
155 157 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
156 158 assert_response :success
157 159 assert_template 'diff'
158 160 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
159 161 :content => /before_filter :require_login/
160 162 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
161 163 :content => /with one change/
162 164 end
163 165 end
164 166
165 167 def test_diff_new_files
166 168 assert_equal 0, @repository.changesets.count
167 169 @repository.fetch_changesets
168 170 @project.reload
169 171 assert_equal NUM_REV, @repository.changesets.count
170 172 ['inline', 'sbs'].each do |dt|
171 173 get :diff, :id => PRJ_ID, :rev => 1, :type => dt
172 174 assert_response :success
173 175 assert_template 'diff'
174 176 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
175 177 :content => /watched.remove_watcher/
176 178 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
177 179 :content => /test\/README/
178 180 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
179 181 :content => /test\/images\/delete.png /
180 182 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
181 183 :content => /test\/images\/edit.png/
182 184 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
183 185 :content => /test\/sources\/watchers_controller.rb/
184 186 end
185 187 end
186 188
187 189 def test_annotate
188 190 assert_equal 0, @repository.changesets.count
189 191 @repository.fetch_changesets
190 192 @project.reload
191 193 assert_equal NUM_REV, @repository.changesets.count
192 194 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
193 195 assert_response :success
194 196 assert_template 'annotate'
195 197 # 1.1 line
196 198 assert_tag :tag => 'th',
197 199 :attributes => { :class => 'line-num' },
198 200 :content => '18',
199 201 :sibling => {
200 202 :tag => 'td',
201 203 :attributes => { :class => 'revision' },
202 204 :content => /1.1/,
203 205 :sibling => {
204 206 :tag => 'td',
205 207 :attributes => { :class => 'author' },
206 208 :content => /LANG/
207 209 }
208 210 }
209 211 # 1.2 line
210 212 assert_tag :tag => 'th',
211 213 :attributes => { :class => 'line-num' },
212 214 :content => '32',
213 215 :sibling => {
214 216 :tag => 'td',
215 217 :attributes => { :class => 'revision' },
216 218 :content => /1.2/,
217 219 :sibling => {
218 220 :tag => 'td',
219 221 :attributes => { :class => 'author' },
220 222 :content => /LANG/
221 223 }
222 224 }
223 225 end
224 226
225 227 def test_destroy_valid_repository
226 228 @request.session[:user_id] = 1 # admin
227 229 assert_equal 0, @repository.changesets.count
228 230 @repository.fetch_changesets
229 231 @project.reload
230 232 assert_equal NUM_REV, @repository.changesets.count
231 233
232 234 get :destroy, :id => PRJ_ID
233 235 assert_response 302
234 236 @project.reload
235 237 assert_nil @project.repository
236 238 end
237 239
238 240 def test_destroy_invalid_repository
239 241 @request.session[:user_id] = 1 # admin
240 242 assert_equal 0, @repository.changesets.count
241 243 @repository.fetch_changesets
242 244 @project.reload
243 245 assert_equal NUM_REV, @repository.changesets.count
244 246
245 247 get :destroy, :id => PRJ_ID
246 248 assert_response 302
247 249 @project.reload
248 250 assert_nil @project.repository
249 251
250 252 @repository = Repository::Cvs.create(
251 253 :project => Project.find(PRJ_ID),
252 254 :root_url => "/invalid",
253 255 :url => MODULE_NAME,
254 256 :log_encoding => 'UTF-8'
255 257 )
256 258 assert @repository
257 259 @repository.fetch_changesets
258 260 @project.reload
259 261 assert_equal 0, @repository.changesets.count
260 262
261 263 get :destroy, :id => PRJ_ID
262 264 assert_response 302
263 265 @project.reload
264 266 assert_nil @project.repository
265 267 end
266 268 else
267 269 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
268 270 def test_fake; assert true end
269 271 end
270 272 end
General Comments 0
You need to be logged in to leave comments. Login now