Chris@441
|
1 # Redmine - project management software
|
Chris@1494
|
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@441
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@441
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19
|
Chris@0
|
20 class RepositoriesCvsControllerTest < ActionController::TestCase
|
Chris@1115
|
21 tests RepositoriesController
|
Chris@1115
|
22
|
Chris@909
|
23 fixtures :projects, :users, :roles, :members, :member_roles,
|
Chris@909
|
24 :repositories, :enabled_modules
|
Chris@0
|
25
|
Chris@909
|
26 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
|
Chris@0
|
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
|
Chris@0
|
28 # CVS module
|
Chris@0
|
29 MODULE_NAME = 'test'
|
Chris@210
|
30 PRJ_ID = 3
|
Chris@909
|
31 NUM_REV = 7
|
Chris@210
|
32
|
Chris@0
|
33 def setup
|
Chris@0
|
34 Setting.default_language = 'en'
|
Chris@0
|
35 User.current = nil
|
Chris@0
|
36
|
Chris@210
|
37 @project = Project.find(PRJ_ID)
|
Chris@441
|
38 @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
|
Chris@441
|
39 :root_url => REPOSITORY_PATH,
|
Chris@441
|
40 :url => MODULE_NAME,
|
Chris@245
|
41 :log_encoding => 'UTF-8')
|
Chris@210
|
42 assert @repository
|
Chris@0
|
43 end
|
Chris@441
|
44
|
Chris@0
|
45 if File.directory?(REPOSITORY_PATH)
|
Chris@1115
|
46 def test_get_new
|
Chris@1115
|
47 @request.session[:user_id] = 1
|
Chris@1115
|
48 @project.repository.destroy
|
Chris@1115
|
49 get :new, :project_id => 'subproject1', :repository_scm => 'Cvs'
|
Chris@1115
|
50 assert_response :success
|
Chris@1115
|
51 assert_template 'new'
|
Chris@1115
|
52 assert_kind_of Repository::Cvs, assigns(:repository)
|
Chris@1115
|
53 assert assigns(:repository).new_record?
|
Chris@1115
|
54 end
|
Chris@1115
|
55
|
Chris@0
|
56 def test_browse_root
|
Chris@909
|
57 assert_equal 0, @repository.changesets.count
|
Chris@210
|
58 @repository.fetch_changesets
|
Chris@909
|
59 @project.reload
|
Chris@909
|
60 assert_equal NUM_REV, @repository.changesets.count
|
Chris@210
|
61 get :show, :id => PRJ_ID
|
Chris@0
|
62 assert_response :success
|
Chris@0
|
63 assert_template 'show'
|
Chris@0
|
64 assert_not_nil assigns(:entries)
|
Chris@0
|
65 assert_equal 3, assigns(:entries).size
|
Chris@441
|
66
|
Chris@0
|
67 entry = assigns(:entries).detect {|e| e.name == 'images'}
|
Chris@0
|
68 assert_equal 'dir', entry.kind
|
Chris@0
|
69
|
Chris@0
|
70 entry = assigns(:entries).detect {|e| e.name == 'README'}
|
Chris@0
|
71 assert_equal 'file', entry.kind
|
Chris@441
|
72
|
Chris@441
|
73 assert_not_nil assigns(:changesets)
|
Chris@909
|
74 assert assigns(:changesets).size > 0
|
Chris@0
|
75 end
|
Chris@441
|
76
|
Chris@0
|
77 def test_browse_directory
|
Chris@909
|
78 assert_equal 0, @repository.changesets.count
|
Chris@210
|
79 @repository.fetch_changesets
|
Chris@909
|
80 @project.reload
|
Chris@909
|
81 assert_equal NUM_REV, @repository.changesets.count
|
Chris@1115
|
82 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
|
Chris@0
|
83 assert_response :success
|
Chris@0
|
84 assert_template 'show'
|
Chris@0
|
85 assert_not_nil assigns(:entries)
|
Chris@0
|
86 assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
|
Chris@0
|
87 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
|
Chris@0
|
88 assert_not_nil entry
|
Chris@0
|
89 assert_equal 'file', entry.kind
|
Chris@0
|
90 assert_equal 'images/edit.png', entry.path
|
Chris@0
|
91 end
|
Chris@441
|
92
|
Chris@0
|
93 def test_browse_at_given_revision
|
Chris@909
|
94 assert_equal 0, @repository.changesets.count
|
Chris@210
|
95 @repository.fetch_changesets
|
Chris@909
|
96 @project.reload
|
Chris@909
|
97 assert_equal NUM_REV, @repository.changesets.count
|
Chris@1115
|
98 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
|
Chris@1115
|
99 :rev => 1
|
Chris@0
|
100 assert_response :success
|
Chris@0
|
101 assert_template 'show'
|
Chris@0
|
102 assert_not_nil assigns(:entries)
|
Chris@0
|
103 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
|
Chris@0
|
104 end
|
Chris@441
|
105
|
Chris@0
|
106 def test_entry
|
Chris@909
|
107 assert_equal 0, @repository.changesets.count
|
Chris@210
|
108 @repository.fetch_changesets
|
Chris@909
|
109 @project.reload
|
Chris@909
|
110 assert_equal NUM_REV, @repository.changesets.count
|
Chris@1115
|
111 get :entry, :id => PRJ_ID,
|
Chris@1115
|
112 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
|
Chris@0
|
113 assert_response :success
|
Chris@0
|
114 assert_template 'entry'
|
Chris@441
|
115 assert_no_tag :tag => 'td',
|
Chris@441
|
116 :attributes => { :class => /line-code/},
|
Chris@441
|
117 :content => /before_filter/
|
Chris@0
|
118 end
|
Chris@441
|
119
|
Chris@0
|
120 def test_entry_at_given_revision
|
Chris@0
|
121 # changesets must be loaded
|
Chris@909
|
122 assert_equal 0, @repository.changesets.count
|
Chris@210
|
123 @repository.fetch_changesets
|
Chris@909
|
124 @project.reload
|
Chris@909
|
125 assert_equal NUM_REV, @repository.changesets.count
|
Chris@1115
|
126 get :entry, :id => PRJ_ID,
|
Chris@1115
|
127 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
|
Chris@1115
|
128 :rev => 2
|
Chris@0
|
129 assert_response :success
|
Chris@0
|
130 assert_template 'entry'
|
Chris@0
|
131 # this line was removed in r3
|
Chris@441
|
132 assert_tag :tag => 'td',
|
Chris@441
|
133 :attributes => { :class => /line-code/},
|
Chris@441
|
134 :content => /before_filter/
|
Chris@0
|
135 end
|
Chris@441
|
136
|
Chris@0
|
137 def test_entry_not_found
|
Chris@909
|
138 assert_equal 0, @repository.changesets.count
|
Chris@210
|
139 @repository.fetch_changesets
|
Chris@909
|
140 @project.reload
|
Chris@909
|
141 assert_equal NUM_REV, @repository.changesets.count
|
Chris@1115
|
142 get :entry, :id => PRJ_ID,
|
Chris@1115
|
143 :path => repository_path_hash(['sources', 'zzz.c'])[:param]
|
Chris@441
|
144 assert_tag :tag => 'p',
|
Chris@441
|
145 :attributes => { :id => /errorExplanation/ },
|
Chris@441
|
146 :content => /The entry or revision was not found in the repository/
|
Chris@0
|
147 end
|
Chris@441
|
148
|
Chris@0
|
149 def test_entry_download
|
Chris@909
|
150 assert_equal 0, @repository.changesets.count
|
Chris@210
|
151 @repository.fetch_changesets
|
Chris@909
|
152 @project.reload
|
Chris@909
|
153 assert_equal NUM_REV, @repository.changesets.count
|
Chris@1115
|
154 get :entry, :id => PRJ_ID,
|
Chris@1115
|
155 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
|
Chris@909
|
156 :format => 'raw'
|
Chris@0
|
157 assert_response :success
|
Chris@0
|
158 end
|
Chris@0
|
159
|
Chris@0
|
160 def test_directory_entry
|
Chris@909
|
161 assert_equal 0, @repository.changesets.count
|
Chris@210
|
162 @repository.fetch_changesets
|
Chris@909
|
163 @project.reload
|
Chris@909
|
164 assert_equal NUM_REV, @repository.changesets.count
|
Chris@1115
|
165 get :entry, :id => PRJ_ID,
|
Chris@1115
|
166 :path => repository_path_hash(['sources'])[:param]
|
Chris@0
|
167 assert_response :success
|
Chris@0
|
168 assert_template 'show'
|
Chris@0
|
169 assert_not_nil assigns(:entry)
|
Chris@0
|
170 assert_equal 'sources', assigns(:entry).name
|
Chris@0
|
171 end
|
Chris@441
|
172
|
Chris@0
|
173 def test_diff
|
Chris@909
|
174 assert_equal 0, @repository.changesets.count
|
Chris@210
|
175 @repository.fetch_changesets
|
Chris@909
|
176 @project.reload
|
Chris@909
|
177 assert_equal NUM_REV, @repository.changesets.count
|
Chris@909
|
178 ['inline', 'sbs'].each do |dt|
|
Chris@909
|
179 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
|
Chris@909
|
180 assert_response :success
|
Chris@909
|
181 assert_template 'diff'
|
Chris@909
|
182 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
|
Chris@909
|
183 :content => /before_filter :require_login/
|
Chris@909
|
184 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
|
Chris@909
|
185 :content => /with one change/
|
Chris@909
|
186 end
|
Chris@0
|
187 end
|
Chris@441
|
188
|
Chris@245
|
189 def test_diff_new_files
|
Chris@909
|
190 assert_equal 0, @repository.changesets.count
|
Chris@245
|
191 @repository.fetch_changesets
|
Chris@909
|
192 @project.reload
|
Chris@909
|
193 assert_equal NUM_REV, @repository.changesets.count
|
Chris@909
|
194 ['inline', 'sbs'].each do |dt|
|
Chris@909
|
195 get :diff, :id => PRJ_ID, :rev => 1, :type => dt
|
Chris@909
|
196 assert_response :success
|
Chris@909
|
197 assert_template 'diff'
|
Chris@909
|
198 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
|
Chris@909
|
199 :content => /watched.remove_watcher/
|
Chris@909
|
200 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
|
Chris@909
|
201 :content => /test\/README/
|
Chris@909
|
202 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
|
Chris@909
|
203 :content => /test\/images\/delete.png /
|
Chris@909
|
204 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
|
Chris@909
|
205 :content => /test\/images\/edit.png/
|
Chris@909
|
206 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
|
Chris@909
|
207 :content => /test\/sources\/watchers_controller.rb/
|
Chris@909
|
208 end
|
Chris@245
|
209 end
|
Chris@0
|
210
|
Chris@0
|
211 def test_annotate
|
Chris@909
|
212 assert_equal 0, @repository.changesets.count
|
Chris@210
|
213 @repository.fetch_changesets
|
Chris@909
|
214 @project.reload
|
Chris@909
|
215 assert_equal NUM_REV, @repository.changesets.count
|
Chris@1115
|
216 get :annotate, :id => PRJ_ID,
|
Chris@1115
|
217 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
|
Chris@0
|
218 assert_response :success
|
Chris@0
|
219 assert_template 'annotate'
|
Chris@1115
|
220
|
Chris@0
|
221 # 1.1 line
|
Chris@1115
|
222 assert_select 'tr' do
|
Chris@1115
|
223 assert_select 'th.line-num', :text => '21'
|
Chris@1115
|
224 assert_select 'td.revision', :text => /1.1/
|
Chris@1115
|
225 assert_select 'td.author', :text => /LANG/
|
Chris@1115
|
226 end
|
Chris@0
|
227 # 1.2 line
|
Chris@1115
|
228 assert_select 'tr' do
|
Chris@1115
|
229 assert_select 'th.line-num', :text => '32'
|
Chris@1115
|
230 assert_select 'td.revision', :text => /1.2/
|
Chris@1115
|
231 assert_select 'td.author', :text => /LANG/
|
Chris@1115
|
232 end
|
Chris@0
|
233 end
|
Chris@909
|
234
|
Chris@909
|
235 def test_destroy_valid_repository
|
Chris@909
|
236 @request.session[:user_id] = 1 # admin
|
Chris@909
|
237 assert_equal 0, @repository.changesets.count
|
Chris@909
|
238 @repository.fetch_changesets
|
Chris@909
|
239 @project.reload
|
Chris@909
|
240 assert_equal NUM_REV, @repository.changesets.count
|
Chris@909
|
241
|
Chris@1115
|
242 assert_difference 'Repository.count', -1 do
|
Chris@1115
|
243 delete :destroy, :id => @repository.id
|
Chris@1115
|
244 end
|
Chris@909
|
245 assert_response 302
|
Chris@909
|
246 @project.reload
|
Chris@909
|
247 assert_nil @project.repository
|
Chris@909
|
248 end
|
Chris@909
|
249
|
Chris@909
|
250 def test_destroy_invalid_repository
|
Chris@909
|
251 @request.session[:user_id] = 1 # admin
|
Chris@1115
|
252 @project.repository.destroy
|
Chris@1115
|
253 @repository = Repository::Cvs.create!(
|
Chris@909
|
254 :project => Project.find(PRJ_ID),
|
Chris@909
|
255 :root_url => "/invalid",
|
Chris@909
|
256 :url => MODULE_NAME,
|
Chris@909
|
257 :log_encoding => 'UTF-8'
|
Chris@909
|
258 )
|
Chris@909
|
259 @repository.fetch_changesets
|
Chris@909
|
260 @project.reload
|
Chris@909
|
261 assert_equal 0, @repository.changesets.count
|
Chris@909
|
262
|
Chris@1115
|
263 assert_difference 'Repository.count', -1 do
|
Chris@1115
|
264 delete :destroy, :id => @repository.id
|
Chris@1115
|
265 end
|
Chris@909
|
266 assert_response 302
|
Chris@909
|
267 @project.reload
|
Chris@909
|
268 assert_nil @project.repository
|
Chris@909
|
269 end
|
Chris@0
|
270 else
|
Chris@0
|
271 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
|
Chris@0
|
272 def test_fake; assert true end
|
Chris@0
|
273 end
|
Chris@0
|
274 end
|