comparison .svn/pristine/e6/e69e1b12c742c2fed3eb747a9348573816cd63d1.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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