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