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