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