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