comparison .svn/pristine/7d/7d7a63dac05990ebb68fcd3fce0da9965a2d6f7a.svn-base @ 909:cbb26bc654de redmine-1.3

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