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