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