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