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