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