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