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