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