##// END OF EJS Templates
Use assert_select instead of assert_tag....
Jean-Philippe Lang -
r9923:71c5d6c8ee4c
parent child
Show More
@@ -1,289 +1,274
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 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
20 20 class RepositoriesCvsControllerTest < ActionController::TestCase
21 21 tests RepositoriesController
22 22
23 23 fixtures :projects, :users, :roles, :members, :member_roles,
24 24 :repositories, :enabled_modules
25 25
26 26 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
27 27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 28 # CVS module
29 29 MODULE_NAME = 'test'
30 30 PRJ_ID = 3
31 31 NUM_REV = 7
32 32
33 33 def setup
34 34 Setting.default_language = 'en'
35 35 User.current = nil
36 36
37 37 @project = Project.find(PRJ_ID)
38 38 @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
39 39 :root_url => REPOSITORY_PATH,
40 40 :url => MODULE_NAME,
41 41 :log_encoding => 'UTF-8')
42 42 assert @repository
43 43 end
44 44
45 45 if File.directory?(REPOSITORY_PATH)
46 46 def test_get_new
47 47 @request.session[:user_id] = 1
48 48 @project.repository.destroy
49 49 get :new, :project_id => 'subproject1', :repository_scm => 'Cvs'
50 50 assert_response :success
51 51 assert_template 'new'
52 52 assert_kind_of Repository::Cvs, assigns(:repository)
53 53 assert assigns(:repository).new_record?
54 54 end
55 55
56 56 def test_browse_root
57 57 assert_equal 0, @repository.changesets.count
58 58 @repository.fetch_changesets
59 59 @project.reload
60 60 assert_equal NUM_REV, @repository.changesets.count
61 61 get :show, :id => PRJ_ID
62 62 assert_response :success
63 63 assert_template 'show'
64 64 assert_not_nil assigns(:entries)
65 65 assert_equal 3, assigns(:entries).size
66 66
67 67 entry = assigns(:entries).detect {|e| e.name == 'images'}
68 68 assert_equal 'dir', entry.kind
69 69
70 70 entry = assigns(:entries).detect {|e| e.name == 'README'}
71 71 assert_equal 'file', entry.kind
72 72
73 73 assert_not_nil assigns(:changesets)
74 74 assert assigns(:changesets).size > 0
75 75 end
76 76
77 77 def test_browse_directory
78 78 assert_equal 0, @repository.changesets.count
79 79 @repository.fetch_changesets
80 80 @project.reload
81 81 assert_equal NUM_REV, @repository.changesets.count
82 82 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
83 83 assert_response :success
84 84 assert_template 'show'
85 85 assert_not_nil assigns(:entries)
86 86 assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
87 87 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
88 88 assert_not_nil entry
89 89 assert_equal 'file', entry.kind
90 90 assert_equal 'images/edit.png', entry.path
91 91 end
92 92
93 93 def test_browse_at_given_revision
94 94 assert_equal 0, @repository.changesets.count
95 95 @repository.fetch_changesets
96 96 @project.reload
97 97 assert_equal NUM_REV, @repository.changesets.count
98 98 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
99 99 :rev => 1
100 100 assert_response :success
101 101 assert_template 'show'
102 102 assert_not_nil assigns(:entries)
103 103 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
104 104 end
105 105
106 106 def test_entry
107 107 assert_equal 0, @repository.changesets.count
108 108 @repository.fetch_changesets
109 109 @project.reload
110 110 assert_equal NUM_REV, @repository.changesets.count
111 111 get :entry, :id => PRJ_ID,
112 112 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
113 113 assert_response :success
114 114 assert_template 'entry'
115 115 assert_no_tag :tag => 'td',
116 116 :attributes => { :class => /line-code/},
117 117 :content => /before_filter/
118 118 end
119 119
120 120 def test_entry_at_given_revision
121 121 # changesets must be loaded
122 122 assert_equal 0, @repository.changesets.count
123 123 @repository.fetch_changesets
124 124 @project.reload
125 125 assert_equal NUM_REV, @repository.changesets.count
126 126 get :entry, :id => PRJ_ID,
127 127 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
128 128 :rev => 2
129 129 assert_response :success
130 130 assert_template 'entry'
131 131 # this line was removed in r3
132 132 assert_tag :tag => 'td',
133 133 :attributes => { :class => /line-code/},
134 134 :content => /before_filter/
135 135 end
136 136
137 137 def test_entry_not_found
138 138 assert_equal 0, @repository.changesets.count
139 139 @repository.fetch_changesets
140 140 @project.reload
141 141 assert_equal NUM_REV, @repository.changesets.count
142 142 get :entry, :id => PRJ_ID,
143 143 :path => repository_path_hash(['sources', 'zzz.c'])[:param]
144 144 assert_tag :tag => 'p',
145 145 :attributes => { :id => /errorExplanation/ },
146 146 :content => /The entry or revision was not found in the repository/
147 147 end
148 148
149 149 def test_entry_download
150 150 assert_equal 0, @repository.changesets.count
151 151 @repository.fetch_changesets
152 152 @project.reload
153 153 assert_equal NUM_REV, @repository.changesets.count
154 154 get :entry, :id => PRJ_ID,
155 155 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
156 156 :format => 'raw'
157 157 assert_response :success
158 158 end
159 159
160 160 def test_directory_entry
161 161 assert_equal 0, @repository.changesets.count
162 162 @repository.fetch_changesets
163 163 @project.reload
164 164 assert_equal NUM_REV, @repository.changesets.count
165 165 get :entry, :id => PRJ_ID,
166 166 :path => repository_path_hash(['sources'])[:param]
167 167 assert_response :success
168 168 assert_template 'show'
169 169 assert_not_nil assigns(:entry)
170 170 assert_equal 'sources', assigns(:entry).name
171 171 end
172 172
173 173 def test_diff
174 174 assert_equal 0, @repository.changesets.count
175 175 @repository.fetch_changesets
176 176 @project.reload
177 177 assert_equal NUM_REV, @repository.changesets.count
178 178 ['inline', 'sbs'].each do |dt|
179 179 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
180 180 assert_response :success
181 181 assert_template 'diff'
182 182 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
183 183 :content => /before_filter :require_login/
184 184 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
185 185 :content => /with one change/
186 186 end
187 187 end
188 188
189 189 def test_diff_new_files
190 190 assert_equal 0, @repository.changesets.count
191 191 @repository.fetch_changesets
192 192 @project.reload
193 193 assert_equal NUM_REV, @repository.changesets.count
194 194 ['inline', 'sbs'].each do |dt|
195 195 get :diff, :id => PRJ_ID, :rev => 1, :type => dt
196 196 assert_response :success
197 197 assert_template 'diff'
198 198 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
199 199 :content => /watched.remove_watcher/
200 200 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
201 201 :content => /test\/README/
202 202 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
203 203 :content => /test\/images\/delete.png /
204 204 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
205 205 :content => /test\/images\/edit.png/
206 206 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
207 207 :content => /test\/sources\/watchers_controller.rb/
208 208 end
209 209 end
210 210
211 211 def test_annotate
212 212 assert_equal 0, @repository.changesets.count
213 213 @repository.fetch_changesets
214 214 @project.reload
215 215 assert_equal NUM_REV, @repository.changesets.count
216 216 get :annotate, :id => PRJ_ID,
217 217 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
218 218 assert_response :success
219 219 assert_template 'annotate'
220
220 221 # 1.1 line
221 assert_tag :tag => 'th',
222 :attributes => { :class => 'line-num' },
223 :content => '21',
224 :sibling => {
225 :tag => 'td',
226 :attributes => { :class => 'revision' },
227 :content => /1.1/,
228 :sibling => {
229 :tag => 'td',
230 :attributes => { :class => 'author' },
231 :content => /LANG/
232 }
233 }
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
234 227 # 1.2 line
235 assert_tag :tag => 'th',
236 :attributes => { :class => 'line-num' },
237 :content => '32',
238 :sibling => {
239 :tag => 'td',
240 :attributes => { :class => 'revision' },
241 :content => /1.2/,
242 :sibling => {
243 :tag => 'td',
244 :attributes => { :class => 'author' },
245 :content => /LANG/
246 }
247 }
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
248 233 end
249 234
250 235 def test_destroy_valid_repository
251 236 @request.session[:user_id] = 1 # admin
252 237 assert_equal 0, @repository.changesets.count
253 238 @repository.fetch_changesets
254 239 @project.reload
255 240 assert_equal NUM_REV, @repository.changesets.count
256 241
257 242 assert_difference 'Repository.count', -1 do
258 243 delete :destroy, :id => @repository.id
259 244 end
260 245 assert_response 302
261 246 @project.reload
262 247 assert_nil @project.repository
263 248 end
264 249
265 250 def test_destroy_invalid_repository
266 251 @request.session[:user_id] = 1 # admin
267 252 @project.repository.destroy
268 253 @repository = Repository::Cvs.create!(
269 254 :project => Project.find(PRJ_ID),
270 255 :root_url => "/invalid",
271 256 :url => MODULE_NAME,
272 257 :log_encoding => 'UTF-8'
273 258 )
274 259 @repository.fetch_changesets
275 260 @project.reload
276 261 assert_equal 0, @repository.changesets.count
277 262
278 263 assert_difference 'Repository.count', -1 do
279 264 delete :destroy, :id => @repository.id
280 265 end
281 266 assert_response 302
282 267 @project.reload
283 268 assert_nil @project.repository
284 269 end
285 270 else
286 271 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
287 272 def test_fake; assert true end
288 273 end
289 274 end
@@ -1,547 +1,534
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 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
20 20 class RepositoriesGitControllerTest < ActionController::TestCase
21 21 tests RepositoriesController
22 22
23 23 fixtures :projects, :users, :roles, :members, :member_roles,
24 24 :repositories, :enabled_modules
25 25
26 26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
27 27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 28 PRJ_ID = 3
29 29 CHAR_1_HEX = "\xc3\x9c"
30 30 NUM_REV = 28
31 31
32 32 ## Git, Mercurial and CVS path encodings are binary.
33 33 ## Subversion supports URL encoding for path.
34 34 ## Redmine Mercurial adapter and extension use URL encoding.
35 35 ## Git accepts only binary path in command line parameter.
36 36 ## So, there is no way to use binary command line parameter in JRuby.
37 37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
38 38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
39 39
40 40 def setup
41 41 @ruby19_non_utf8_pass =
42 42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
43 43
44 44 User.current = nil
45 45 @project = Project.find(PRJ_ID)
46 46 @repository = Repository::Git.create(
47 47 :project => @project,
48 48 :url => REPOSITORY_PATH,
49 49 :path_encoding => 'ISO-8859-1'
50 50 )
51 51 assert @repository
52 52 @char_1 = CHAR_1_HEX.dup
53 53 if @char_1.respond_to?(:force_encoding)
54 54 @char_1.force_encoding('UTF-8')
55 55 end
56 56
57 57 Setting.default_language = 'en'
58 58 end
59 59
60 60 def test_create_and_update
61 61 @request.session[:user_id] = 1
62 62 assert_difference 'Repository.count' do
63 63 post :create, :project_id => 'subproject1',
64 64 :repository_scm => 'Git',
65 65 :repository => {
66 66 :url => '/test',
67 67 :is_default => '0',
68 68 :identifier => 'test-create',
69 69 :extra_report_last_commit => '1',
70 70 }
71 71 end
72 72 assert_response 302
73 73 repository = Repository.first(:order => 'id DESC')
74 74 assert_kind_of Repository::Git, repository
75 75 assert_equal '/test', repository.url
76 76 assert_equal true, repository.extra_report_last_commit
77 77
78 78 put :update, :id => repository.id,
79 79 :repository => {
80 80 :extra_report_last_commit => '0'
81 81 }
82 82 assert_response 302
83 83 repo2 = Repository.find(repository.id)
84 84 assert_equal false, repo2.extra_report_last_commit
85 85 end
86 86
87 87 if File.directory?(REPOSITORY_PATH)
88 88 ## Ruby uses ANSI api to fork a process on Windows.
89 89 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
90 90 ## and these are incompatible with ASCII.
91 91 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
92 92 ## http://code.google.com/p/msysgit/issues/detail?id=80
93 93 ## So, Latin-1 path tests fail on Japanese Windows
94 94 WINDOWS_PASS = (Redmine::Platform.mswin? &&
95 95 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
96 96 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
97 97
98 98 def test_get_new
99 99 @request.session[:user_id] = 1
100 100 @project.repository.destroy
101 101 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
102 102 assert_response :success
103 103 assert_template 'new'
104 104 assert_kind_of Repository::Git, assigns(:repository)
105 105 assert assigns(:repository).new_record?
106 106 end
107 107
108 108 def test_browse_root
109 109 assert_equal 0, @repository.changesets.count
110 110 @repository.fetch_changesets
111 111 @project.reload
112 112 assert_equal NUM_REV, @repository.changesets.count
113 113
114 114 get :show, :id => PRJ_ID
115 115 assert_response :success
116 116 assert_template 'show'
117 117 assert_not_nil assigns(:entries)
118 118 assert_equal 9, assigns(:entries).size
119 119 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
120 120 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
121 121 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
122 122 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
123 123 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
124 124 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
125 125 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
126 126 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
127 127 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
128 128 assert_not_nil assigns(:changesets)
129 129 assert assigns(:changesets).size > 0
130 130 end
131 131
132 132 def test_browse_branch
133 133 assert_equal 0, @repository.changesets.count
134 134 @repository.fetch_changesets
135 135 @project.reload
136 136 assert_equal NUM_REV, @repository.changesets.count
137 137 get :show, :id => PRJ_ID, :rev => 'test_branch'
138 138 assert_response :success
139 139 assert_template 'show'
140 140 assert_not_nil assigns(:entries)
141 141 assert_equal 4, assigns(:entries).size
142 142 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
143 143 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
144 144 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
145 145 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
146 146 assert_not_nil assigns(:changesets)
147 147 assert assigns(:changesets).size > 0
148 148 end
149 149
150 150 def test_browse_tag
151 151 assert_equal 0, @repository.changesets.count
152 152 @repository.fetch_changesets
153 153 @project.reload
154 154 assert_equal NUM_REV, @repository.changesets.count
155 155 [
156 156 "tag00.lightweight",
157 157 "tag01.annotated",
158 158 ].each do |t1|
159 159 get :show, :id => PRJ_ID, :rev => t1
160 160 assert_response :success
161 161 assert_template 'show'
162 162 assert_not_nil assigns(:entries)
163 163 assert assigns(:entries).size > 0
164 164 assert_not_nil assigns(:changesets)
165 165 assert assigns(:changesets).size > 0
166 166 end
167 167 end
168 168
169 169 def test_browse_directory
170 170 assert_equal 0, @repository.changesets.count
171 171 @repository.fetch_changesets
172 172 @project.reload
173 173 assert_equal NUM_REV, @repository.changesets.count
174 174 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
175 175 assert_response :success
176 176 assert_template 'show'
177 177 assert_not_nil assigns(:entries)
178 178 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
179 179 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
180 180 assert_not_nil entry
181 181 assert_equal 'file', entry.kind
182 182 assert_equal 'images/edit.png', entry.path
183 183 assert_not_nil assigns(:changesets)
184 184 assert assigns(:changesets).size > 0
185 185 end
186 186
187 187 def test_browse_at_given_revision
188 188 assert_equal 0, @repository.changesets.count
189 189 @repository.fetch_changesets
190 190 @project.reload
191 191 assert_equal NUM_REV, @repository.changesets.count
192 192 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
193 193 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
194 194 assert_response :success
195 195 assert_template 'show'
196 196 assert_not_nil assigns(:entries)
197 197 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
198 198 assert_not_nil assigns(:changesets)
199 199 assert assigns(:changesets).size > 0
200 200 end
201 201
202 202 def test_changes
203 203 get :changes, :id => PRJ_ID,
204 204 :path => repository_path_hash(['images', 'edit.png'])[:param]
205 205 assert_response :success
206 206 assert_template 'changes'
207 207 assert_tag :tag => 'h2', :content => 'edit.png'
208 208 end
209 209
210 210 def test_entry_show
211 211 get :entry, :id => PRJ_ID,
212 212 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
213 213 assert_response :success
214 214 assert_template 'entry'
215 215 # Line 19
216 216 assert_tag :tag => 'th',
217 217 :content => '11',
218 218 :attributes => { :class => 'line-num' },
219 219 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
220 220 end
221 221
222 222 def test_entry_show_latin_1
223 223 if @ruby19_non_utf8_pass
224 224 puts_ruby19_non_utf8_pass()
225 225 elsif WINDOWS_PASS
226 226 puts WINDOWS_SKIP_STR
227 227 elsif JRUBY_SKIP
228 228 puts JRUBY_SKIP_STR
229 229 else
230 230 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
231 231 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
232 232 get :entry, :id => PRJ_ID,
233 233 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
234 234 :rev => r1
235 235 assert_response :success
236 236 assert_template 'entry'
237 237 assert_tag :tag => 'th',
238 238 :content => '1',
239 239 :attributes => { :class => 'line-num' },
240 240 :sibling => { :tag => 'td',
241 241 :content => /test-#{@char_1}.txt/ }
242 242 end
243 243 end
244 244 end
245 245 end
246 246
247 247 def test_entry_download
248 248 get :entry, :id => PRJ_ID,
249 249 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
250 250 :format => 'raw'
251 251 assert_response :success
252 252 # File content
253 253 assert @response.body.include?('WITHOUT ANY WARRANTY')
254 254 end
255 255
256 256 def test_directory_entry
257 257 get :entry, :id => PRJ_ID,
258 258 :path => repository_path_hash(['sources'])[:param]
259 259 assert_response :success
260 260 assert_template 'show'
261 261 assert_not_nil assigns(:entry)
262 262 assert_equal 'sources', assigns(:entry).name
263 263 end
264 264
265 265 def test_diff
266 266 assert_equal 0, @repository.changesets.count
267 267 @repository.fetch_changesets
268 268 @project.reload
269 269 assert_equal NUM_REV, @repository.changesets.count
270 270 # Full diff of changeset 2f9c0091
271 271 ['inline', 'sbs'].each do |dt|
272 272 get :diff,
273 273 :id => PRJ_ID,
274 274 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
275 275 :type => dt
276 276 assert_response :success
277 277 assert_template 'diff'
278 278 # Line 22 removed
279 279 assert_tag :tag => 'th',
280 280 :content => /22/,
281 281 :sibling => { :tag => 'td',
282 282 :attributes => { :class => /diff_out/ },
283 283 :content => /def remove/ }
284 284 assert_tag :tag => 'h2', :content => /2f9c0091/
285 285 end
286 286 end
287 287
288 288 def test_diff_truncated
289 289 assert_equal 0, @repository.changesets.count
290 290 @repository.fetch_changesets
291 291 @project.reload
292 292 assert_equal NUM_REV, @repository.changesets.count
293 293
294 294 with_settings :diff_max_lines_displayed => 5 do
295 295 # Truncated diff of changeset 2f9c0091
296 296 with_cache do
297 297 get :diff, :id => PRJ_ID, :type => 'inline',
298 298 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
299 299 assert_response :success
300 300 assert @response.body.include?("... This diff was truncated")
301 301
302 302 Setting.default_language = 'fr'
303 303 get :diff, :id => PRJ_ID, :type => 'inline',
304 304 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
305 305 assert_response :success
306 306 assert ! @response.body.include?("... This diff was truncated")
307 307 assert @response.body.include?("... Ce diff")
308 308 end
309 309 end
310 310 end
311 311
312 312 def test_diff_two_revs
313 313 assert_equal 0, @repository.changesets.count
314 314 @repository.fetch_changesets
315 315 @project.reload
316 316 assert_equal NUM_REV, @repository.changesets.count
317 317 ['inline', 'sbs'].each do |dt|
318 318 get :diff,
319 319 :id => PRJ_ID,
320 320 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
321 321 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
322 322 :type => dt
323 323 assert_response :success
324 324 assert_template 'diff'
325 325 diff = assigns(:diff)
326 326 assert_not_nil diff
327 327 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
328 328 end
329 329 end
330 330
331 331 def test_diff_latin_1
332 332 if @ruby19_non_utf8_pass
333 333 puts_ruby19_non_utf8_pass()
334 334 else
335 335 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
336 336 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
337 337 ['inline', 'sbs'].each do |dt|
338 338 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
339 339 assert_response :success
340 340 assert_template 'diff'
341 341 assert_tag :tag => 'thead',
342 342 :descendant => {
343 343 :tag => 'th',
344 344 :attributes => { :class => 'filename' } ,
345 345 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
346 346 },
347 347 :sibling => {
348 348 :tag => 'tbody',
349 349 :descendant => {
350 350 :tag => 'td',
351 351 :attributes => { :class => /diff_in/ },
352 352 :content => /test-#{@char_1}.txt/
353 353 }
354 354 }
355 355 end
356 356 end
357 357 end
358 358 end
359 359 end
360 360
361 361 def test_save_diff_type
362 362 @request.session[:user_id] = 1 # admin
363 363 user = User.find(1)
364 364 get :diff,
365 365 :id => PRJ_ID,
366 366 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
367 367 assert_response :success
368 368 assert_template 'diff'
369 369 user.reload
370 370 assert_equal "inline", user.pref[:diff_type]
371 371 get :diff,
372 372 :id => PRJ_ID,
373 373 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
374 374 :type => 'sbs'
375 375 assert_response :success
376 376 assert_template 'diff'
377 377 user.reload
378 378 assert_equal "sbs", user.pref[:diff_type]
379 379 end
380 380
381 381 def test_annotate
382 382 get :annotate, :id => PRJ_ID,
383 383 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
384 384 assert_response :success
385 385 assert_template 'annotate'
386
386 387 # Line 23, changeset 2f9c0091
387 assert_tag :tag => 'th', :content => '23',
388 :sibling => {
389 :tag => 'td',
390 :child => {
391 :tag => 'a',
392 :content => /2f9c0091/
393 }
394 }
395 assert_tag :tag => 'th', :content => '23',
396 :sibling => { :tag => 'td', :content => /jsmith/ }
397 assert_tag :tag => 'th', :content => '23',
398 :sibling => {
399 :tag => 'td',
400 :child => {
401 :tag => 'a',
402 :content => /2f9c0091/
403 }
404 }
405 assert_tag :tag => 'th', :content => '23',
406 :sibling => { :tag => 'td', :content => /remove_watcher/ }
388 assert_select 'tr' do
389 assert_select 'th.line-num', :text => '23'
390 assert_select 'td.revision', :text => /2f9c0091/
391 assert_select 'td.author', :text => 'jsmith'
392 assert_select 'td', :text => /remove_watcher/
393 end
407 394 end
408 395
409 396 def test_annotate_at_given_revision
410 397 assert_equal 0, @repository.changesets.count
411 398 @repository.fetch_changesets
412 399 @project.reload
413 400 assert_equal NUM_REV, @repository.changesets.count
414 401 get :annotate, :id => PRJ_ID, :rev => 'deff7',
415 402 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
416 403 assert_response :success
417 404 assert_template 'annotate'
418 405 assert_tag :tag => 'h2', :content => /@ deff712f/
419 406 end
420 407
421 408 def test_annotate_binary_file
422 409 get :annotate, :id => PRJ_ID,
423 410 :path => repository_path_hash(['images', 'edit.png'])[:param]
424 411 assert_response 500
425 412 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
426 413 :content => /cannot be annotated/
427 414 end
428 415
429 416 def test_annotate_error_when_too_big
430 417 with_settings :file_max_size_displayed => 1 do
431 418 get :annotate, :id => PRJ_ID,
432 419 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
433 420 :rev => 'deff712f'
434 421 assert_response 500
435 422 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
436 423 :content => /exceeds the maximum text file size/
437 424
438 425 get :annotate, :id => PRJ_ID,
439 426 :path => repository_path_hash(['README'])[:param],
440 427 :rev => '7234cb2'
441 428 assert_response :success
442 429 assert_template 'annotate'
443 430 end
444 431 end
445 432
446 433 def test_annotate_latin_1
447 434 if @ruby19_non_utf8_pass
448 435 puts_ruby19_non_utf8_pass()
449 436 elsif WINDOWS_PASS
450 437 puts WINDOWS_SKIP_STR
451 438 elsif JRUBY_SKIP
452 439 puts JRUBY_SKIP_STR
453 440 else
454 441 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
455 442 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
456 443 get :annotate, :id => PRJ_ID,
457 444 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
458 445 :rev => r1
459 446 assert_tag :tag => 'th',
460 447 :content => '1',
461 448 :attributes => { :class => 'line-num' },
462 449 :sibling => { :tag => 'td',
463 450 :content => /test-#{@char_1}.txt/ }
464 451 end
465 452 end
466 453 end
467 454 end
468 455
469 456 def test_revision
470 457 assert_equal 0, @repository.changesets.count
471 458 @repository.fetch_changesets
472 459 @project.reload
473 460 assert_equal NUM_REV, @repository.changesets.count
474 461 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
475 462 get :revision, :id => PRJ_ID, :rev => r
476 463 assert_response :success
477 464 assert_template 'revision'
478 465 end
479 466 end
480 467
481 468 def test_empty_revision
482 469 assert_equal 0, @repository.changesets.count
483 470 @repository.fetch_changesets
484 471 @project.reload
485 472 assert_equal NUM_REV, @repository.changesets.count
486 473 ['', ' ', nil].each do |r|
487 474 get :revision, :id => PRJ_ID, :rev => r
488 475 assert_response 404
489 476 assert_error_tag :content => /was not found/
490 477 end
491 478 end
492 479
493 480 def test_destroy_valid_repository
494 481 @request.session[:user_id] = 1 # admin
495 482 assert_equal 0, @repository.changesets.count
496 483 @repository.fetch_changesets
497 484 @project.reload
498 485 assert_equal NUM_REV, @repository.changesets.count
499 486
500 487 assert_difference 'Repository.count', -1 do
501 488 delete :destroy, :id => @repository.id
502 489 end
503 490 assert_response 302
504 491 @project.reload
505 492 assert_nil @project.repository
506 493 end
507 494
508 495 def test_destroy_invalid_repository
509 496 @request.session[:user_id] = 1 # admin
510 497 @project.repository.destroy
511 498 @repository = Repository::Git.create!(
512 499 :project => @project,
513 500 :url => "/invalid",
514 501 :path_encoding => 'ISO-8859-1'
515 502 )
516 503 @repository.fetch_changesets
517 504 @repository.reload
518 505 assert_equal 0, @repository.changesets.count
519 506
520 507 assert_difference 'Repository.count', -1 do
521 508 delete :destroy, :id => @repository.id
522 509 end
523 510 assert_response 302
524 511 @project.reload
525 512 assert_nil @project.repository
526 513 end
527 514
528 515 private
529 516
530 517 def puts_ruby19_non_utf8_pass
531 518 puts "TODO: This test fails in Ruby 1.9 " +
532 519 "and Encoding.default_external is not UTF-8. " +
533 520 "Current value is '#{Encoding.default_external.to_s}'"
534 521 end
535 522 else
536 523 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
537 524 def test_fake; assert true end
538 525 end
539 526
540 527 private
541 528 def with_cache(&block)
542 529 before = ActionController::Base.perform_caching
543 530 ActionController::Base.perform_caching = true
544 531 block.call
545 532 ActionController::Base.perform_caching = before
546 533 end
547 534 end
@@ -1,526 +1,511
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 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
20 20 class RepositoriesMercurialControllerTest < ActionController::TestCase
21 21 tests RepositoriesController
22 22
23 23 fixtures :projects, :users, :roles, :members, :member_roles,
24 24 :repositories, :enabled_modules
25 25
26 26 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
27 27 CHAR_1_HEX = "\xc3\x9c"
28 28 PRJ_ID = 3
29 29 NUM_REV = 32
30 30
31 31 ruby19_non_utf8_pass =
32 32 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
33 33
34 34 def setup
35 35 User.current = nil
36 36 @project = Project.find(PRJ_ID)
37 37 @repository = Repository::Mercurial.create(
38 38 :project => @project,
39 39 :url => REPOSITORY_PATH,
40 40 :path_encoding => 'ISO-8859-1'
41 41 )
42 42 assert @repository
43 43 @diff_c_support = true
44 44 @char_1 = CHAR_1_HEX.dup
45 45 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
46 46 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
47 47 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
48 48 if @char_1.respond_to?(:force_encoding)
49 49 @char_1.force_encoding('UTF-8')
50 50 @tag_char_1.force_encoding('UTF-8')
51 51 @branch_char_0.force_encoding('UTF-8')
52 52 @branch_char_1.force_encoding('UTF-8')
53 53 end
54 54 end
55 55
56 56 if ruby19_non_utf8_pass
57 57 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
58 58 "and Encoding.default_external is not UTF-8. " +
59 59 "Current value is '#{Encoding.default_external.to_s}'"
60 60 def test_fake; assert true end
61 61 elsif File.directory?(REPOSITORY_PATH)
62 62
63 63 def test_get_new
64 64 @request.session[:user_id] = 1
65 65 @project.repository.destroy
66 66 get :new, :project_id => 'subproject1', :repository_scm => 'Mercurial'
67 67 assert_response :success
68 68 assert_template 'new'
69 69 assert_kind_of Repository::Mercurial, assigns(:repository)
70 70 assert assigns(:repository).new_record?
71 71 end
72 72
73 73 def test_show_root
74 74 assert_equal 0, @repository.changesets.count
75 75 @repository.fetch_changesets
76 76 @project.reload
77 77 assert_equal NUM_REV, @repository.changesets.count
78 78 get :show, :id => PRJ_ID
79 79 assert_response :success
80 80 assert_template 'show'
81 81 assert_not_nil assigns(:entries)
82 82 assert_equal 4, assigns(:entries).size
83 83 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
84 84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
85 85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
86 86 assert_not_nil assigns(:changesets)
87 87 assert assigns(:changesets).size > 0
88 88 end
89 89
90 90 def test_show_directory
91 91 assert_equal 0, @repository.changesets.count
92 92 @repository.fetch_changesets
93 93 @project.reload
94 94 assert_equal NUM_REV, @repository.changesets.count
95 95 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
96 96 assert_response :success
97 97 assert_template 'show'
98 98 assert_not_nil assigns(:entries)
99 99 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
100 100 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
101 101 assert_not_nil entry
102 102 assert_equal 'file', entry.kind
103 103 assert_equal 'images/edit.png', entry.path
104 104 assert_not_nil assigns(:changesets)
105 105 assert assigns(:changesets).size > 0
106 106 end
107 107
108 108 def test_show_at_given_revision
109 109 assert_equal 0, @repository.changesets.count
110 110 @repository.fetch_changesets
111 111 @project.reload
112 112 assert_equal NUM_REV, @repository.changesets.count
113 113 [0, '0', '0885933ad4f6'].each do |r1|
114 114 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
115 115 :rev => r1
116 116 assert_response :success
117 117 assert_template 'show'
118 118 assert_not_nil assigns(:entries)
119 119 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
120 120 assert_not_nil assigns(:changesets)
121 121 assert assigns(:changesets).size > 0
122 122 end
123 123 end
124 124
125 125 def test_show_directory_sql_escape_percent
126 126 assert_equal 0, @repository.changesets.count
127 127 @repository.fetch_changesets
128 128 @project.reload
129 129 assert_equal NUM_REV, @repository.changesets.count
130 130 [13, '13', '3a330eb32958'].each do |r1|
131 131 get :show, :id => PRJ_ID,
132 132 :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param],
133 133 :rev => r1
134 134 assert_response :success
135 135 assert_template 'show'
136 136
137 137 assert_not_nil assigns(:entries)
138 138 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
139 139 assigns(:entries).collect(&:name)
140 140 changesets = assigns(:changesets)
141 141 assert_not_nil changesets
142 142 assert assigns(:changesets).size > 0
143 143 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
144 144 end
145 145 end
146 146
147 147 def test_show_directory_latin_1_path
148 148 assert_equal 0, @repository.changesets.count
149 149 @repository.fetch_changesets
150 150 @project.reload
151 151 assert_equal NUM_REV, @repository.changesets.count
152 152 [21, '21', 'adf805632193'].each do |r1|
153 153 get :show, :id => PRJ_ID,
154 154 :path => repository_path_hash(['latin-1-dir'])[:param],
155 155 :rev => r1
156 156 assert_response :success
157 157 assert_template 'show'
158 158
159 159 assert_not_nil assigns(:entries)
160 160 assert_equal ["make-latin-1-file.rb",
161 161 "test-#{@char_1}-1.txt",
162 162 "test-#{@char_1}-2.txt",
163 163 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
164 164 changesets = assigns(:changesets)
165 165 assert_not_nil changesets
166 166 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
167 167 end
168 168 end
169 169
170 170 def show_should_show_branch_selection_form
171 171 @repository.fetch_changesets
172 172 @project.reload
173 173 get :show, :id => PRJ_ID
174 174 assert_tag 'form', :attributes => {:id => 'revision_selector', :action => '/projects/subproject1/repository/show'}
175 175 assert_tag 'select', :attributes => {:name => 'branch'},
176 176 :child => {:tag => 'option', :attributes => {:value => 'test-branch-01'}},
177 177 :parent => {:tag => 'form', :attributes => {:id => 'revision_selector'}}
178 178 end
179 179
180 180 def test_show_branch
181 181 assert_equal 0, @repository.changesets.count
182 182 @repository.fetch_changesets
183 183 @project.reload
184 184 assert_equal NUM_REV, @repository.changesets.count
185 185 [
186 186 'default',
187 187 @branch_char_1,
188 188 'branch (1)[2]&,%.-3_4',
189 189 @branch_char_0,
190 190 'test_branch.latin-1',
191 191 'test-branch-00',
192 192 ].each do |bra|
193 193 get :show, :id => PRJ_ID, :rev => bra
194 194 assert_response :success
195 195 assert_template 'show'
196 196 assert_not_nil assigns(:entries)
197 197 assert assigns(:entries).size > 0
198 198 assert_not_nil assigns(:changesets)
199 199 assert assigns(:changesets).size > 0
200 200 end
201 201 end
202 202
203 203 def test_show_tag
204 204 assert_equal 0, @repository.changesets.count
205 205 @repository.fetch_changesets
206 206 @project.reload
207 207 assert_equal NUM_REV, @repository.changesets.count
208 208 [
209 209 @tag_char_1,
210 210 'tag_test.00',
211 211 'tag-init-revision'
212 212 ].each do |tag|
213 213 get :show, :id => PRJ_ID, :rev => tag
214 214 assert_response :success
215 215 assert_template 'show'
216 216 assert_not_nil assigns(:entries)
217 217 assert assigns(:entries).size > 0
218 218 assert_not_nil assigns(:changesets)
219 219 assert assigns(:changesets).size > 0
220 220 end
221 221 end
222 222
223 223 def test_changes
224 224 get :changes, :id => PRJ_ID,
225 225 :path => repository_path_hash(['images', 'edit.png'])[:param]
226 226 assert_response :success
227 227 assert_template 'changes'
228 228 assert_tag :tag => 'h2', :content => 'edit.png'
229 229 end
230 230
231 231 def test_entry_show
232 232 get :entry, :id => PRJ_ID,
233 233 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
234 234 assert_response :success
235 235 assert_template 'entry'
236 236 # Line 10
237 237 assert_tag :tag => 'th',
238 238 :content => '10',
239 239 :attributes => { :class => 'line-num' },
240 240 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
241 241 end
242 242
243 243 def test_entry_show_latin_1_path
244 244 [21, '21', 'adf805632193'].each do |r1|
245 245 get :entry, :id => PRJ_ID,
246 246 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
247 247 :rev => r1
248 248 assert_response :success
249 249 assert_template 'entry'
250 250 assert_tag :tag => 'th',
251 251 :content => '1',
252 252 :attributes => { :class => 'line-num' },
253 253 :sibling => { :tag => 'td',
254 254 :content => /Mercurial is a distributed version control system/ }
255 255 end
256 256 end
257 257
258 258 def test_entry_show_latin_1_contents
259 259 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
260 260 [27, '27', '7bbf4c738e71'].each do |r1|
261 261 get :entry, :id => PRJ_ID,
262 262 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
263 263 :rev => r1
264 264 assert_response :success
265 265 assert_template 'entry'
266 266 assert_tag :tag => 'th',
267 267 :content => '1',
268 268 :attributes => { :class => 'line-num' },
269 269 :sibling => { :tag => 'td',
270 270 :content => /test-#{@char_1}.txt/ }
271 271 end
272 272 end
273 273 end
274 274
275 275 def test_entry_download
276 276 get :entry, :id => PRJ_ID,
277 277 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
278 278 :format => 'raw'
279 279 assert_response :success
280 280 # File content
281 281 assert @response.body.include?('WITHOUT ANY WARRANTY')
282 282 end
283 283
284 284 def test_entry_binary_force_download
285 285 get :entry, :id => PRJ_ID, :rev => 1,
286 286 :path => repository_path_hash(['images', 'edit.png'])[:param]
287 287 assert_response :success
288 288 assert_equal 'image/png', @response.content_type
289 289 end
290 290
291 291 def test_directory_entry
292 292 get :entry, :id => PRJ_ID,
293 293 :path => repository_path_hash(['sources'])[:param]
294 294 assert_response :success
295 295 assert_template 'show'
296 296 assert_not_nil assigns(:entry)
297 297 assert_equal 'sources', assigns(:entry).name
298 298 end
299 299
300 300 def test_diff
301 301 assert_equal 0, @repository.changesets.count
302 302 @repository.fetch_changesets
303 303 @project.reload
304 304 assert_equal NUM_REV, @repository.changesets.count
305 305 [4, '4', 'def6d2f1254a'].each do |r1|
306 306 # Full diff of changeset 4
307 307 ['inline', 'sbs'].each do |dt|
308 308 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
309 309 assert_response :success
310 310 assert_template 'diff'
311 311 if @diff_c_support
312 312 # Line 22 removed
313 313 assert_tag :tag => 'th',
314 314 :content => '22',
315 315 :sibling => { :tag => 'td',
316 316 :attributes => { :class => /diff_out/ },
317 317 :content => /def remove/ }
318 318 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
319 319 end
320 320 end
321 321 end
322 322 end
323 323
324 324 def test_diff_two_revs
325 325 assert_equal 0, @repository.changesets.count
326 326 @repository.fetch_changesets
327 327 @project.reload
328 328 assert_equal NUM_REV, @repository.changesets.count
329 329 [2, '400bb8672109', '400', 400].each do |r1|
330 330 [4, 'def6d2f1254a'].each do |r2|
331 331 ['inline', 'sbs'].each do |dt|
332 332 get :diff,
333 333 :id => PRJ_ID,
334 334 :rev => r1,
335 335 :rev_to => r2,
336 336 :type => dt
337 337 assert_response :success
338 338 assert_template 'diff'
339 339 diff = assigns(:diff)
340 340 assert_not_nil diff
341 341 assert_tag :tag => 'h2',
342 342 :content => /4:def6d2f1254a 2:400bb8672109/
343 343 end
344 344 end
345 345 end
346 346 end
347 347
348 348 def test_diff_latin_1_path
349 349 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
350 350 [21, 'adf805632193'].each do |r1|
351 351 ['inline', 'sbs'].each do |dt|
352 352 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
353 353 assert_response :success
354 354 assert_template 'diff'
355 355 assert_tag :tag => 'thead',
356 356 :descendant => {
357 357 :tag => 'th',
358 358 :attributes => { :class => 'filename' } ,
359 359 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
360 360 },
361 361 :sibling => {
362 362 :tag => 'tbody',
363 363 :descendant => {
364 364 :tag => 'td',
365 365 :attributes => { :class => /diff_in/ },
366 366 :content => /It is written in Python/
367 367 }
368 368 }
369 369 end
370 370 end
371 371 end
372 372 end
373 373
374 374 def test_annotate
375 375 get :annotate, :id => PRJ_ID,
376 376 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
377 377 assert_response :success
378 378 assert_template 'annotate'
379
379 380 # Line 22, revision 4:def6d2f1254a
380 assert_tag :tag => 'th',
381 :content => '22',
382 :attributes => { :class => 'line-num' },
383 :sibling =>
384 {
385 :tag => 'td',
386 :attributes => { :class => 'revision' },
387 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
388 }
389 assert_tag :tag => 'th',
390 :content => '22',
391 :attributes => { :class => 'line-num' },
392 :sibling =>
393 {
394 :tag => 'td' ,
395 :content => 'jsmith' ,
396 :attributes => { :class => 'author' },
397 }
398 assert_tag :tag => 'th',
399 :content => '22',
400 :attributes => { :class => 'line-num' },
401 :sibling => { :tag => 'td', :content => /remove_watcher/ }
381 assert_select 'tr' do
382 assert_select 'th.line-num', :text => '22'
383 assert_select 'td.revision', :text => '4:def6d2f1254a'
384 assert_select 'td.author', :text => 'jsmith'
385 assert_select 'td', :text => /remove_watcher/
386 end
402 387 end
403 388
404 389 def test_annotate_not_in_tip
405 390 assert_equal 0, @repository.changesets.count
406 391 @repository.fetch_changesets
407 392 @project.reload
408 393 assert_equal NUM_REV, @repository.changesets.count
409 394 get :annotate, :id => PRJ_ID,
410 395 :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param]
411 396 assert_response 404
412 397 assert_error_tag :content => /was not found/
413 398 end
414 399
415 400 def test_annotate_at_given_revision
416 401 assert_equal 0, @repository.changesets.count
417 402 @repository.fetch_changesets
418 403 @project.reload
419 404 assert_equal NUM_REV, @repository.changesets.count
420 405 [2, '400bb8672109', '400', 400].each do |r1|
421 406 get :annotate, :id => PRJ_ID, :rev => r1,
422 407 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
423 408 assert_response :success
424 409 assert_template 'annotate'
425 410 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
426 411 end
427 412 end
428 413
429 414 def test_annotate_latin_1_path
430 415 [21, '21', 'adf805632193'].each do |r1|
431 416 get :annotate, :id => PRJ_ID,
432 417 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
433 418 :rev => r1
434 419 assert_response :success
435 420 assert_template 'annotate'
436 421 assert_tag :tag => 'th',
437 422 :content => '1',
438 423 :attributes => { :class => 'line-num' },
439 424 :sibling =>
440 425 {
441 426 :tag => 'td',
442 427 :attributes => { :class => 'revision' },
443 428 :child => { :tag => 'a', :content => '20:709858aafd1b' }
444 429 }
445 430 assert_tag :tag => 'th',
446 431 :content => '1',
447 432 :attributes => { :class => 'line-num' },
448 433 :sibling =>
449 434 {
450 435 :tag => 'td' ,
451 436 :content => 'jsmith' ,
452 437 :attributes => { :class => 'author' },
453 438 }
454 439 assert_tag :tag => 'th',
455 440 :content => '1',
456 441 :attributes => { :class => 'line-num' },
457 442 :sibling => { :tag => 'td',
458 443 :content => /Mercurial is a distributed version control system/ }
459 444
460 445 end
461 446 end
462 447
463 448 def test_annotate_latin_1_contents
464 449 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
465 450 [27, '7bbf4c738e71'].each do |r1|
466 451 get :annotate, :id => PRJ_ID,
467 452 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
468 453 :rev => r1
469 454 assert_tag :tag => 'th',
470 455 :content => '1',
471 456 :attributes => { :class => 'line-num' },
472 457 :sibling => { :tag => 'td',
473 458 :content => /test-#{@char_1}.txt/ }
474 459 end
475 460 end
476 461 end
477 462
478 463 def test_empty_revision
479 464 assert_equal 0, @repository.changesets.count
480 465 @repository.fetch_changesets
481 466 @project.reload
482 467 assert_equal NUM_REV, @repository.changesets.count
483 468 ['', ' ', nil].each do |r|
484 469 get :revision, :id => PRJ_ID, :rev => r
485 470 assert_response 404
486 471 assert_error_tag :content => /was not found/
487 472 end
488 473 end
489 474
490 475 def test_destroy_valid_repository
491 476 @request.session[:user_id] = 1 # admin
492 477 assert_equal 0, @repository.changesets.count
493 478 @repository.fetch_changesets
494 479 assert_equal NUM_REV, @repository.changesets.count
495 480
496 481 assert_difference 'Repository.count', -1 do
497 482 delete :destroy, :id => @repository.id
498 483 end
499 484 assert_response 302
500 485 @project.reload
501 486 assert_nil @project.repository
502 487 end
503 488
504 489 def test_destroy_invalid_repository
505 490 @request.session[:user_id] = 1 # admin
506 491 @project.repository.destroy
507 492 @repository = Repository::Mercurial.create!(
508 493 :project => Project.find(PRJ_ID),
509 494 :url => "/invalid",
510 495 :path_encoding => 'ISO-8859-1'
511 496 )
512 497 @repository.fetch_changesets
513 498 assert_equal 0, @repository.changesets.count
514 499
515 500 assert_difference 'Repository.count', -1 do
516 501 delete :destroy, :id => @repository.id
517 502 end
518 503 assert_response 302
519 504 @project.reload
520 505 assert_nil @project.repository
521 506 end
522 507 else
523 508 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
524 509 def test_fake; assert true end
525 510 end
526 511 end
General Comments 0
You need to be logged in to leave comments. Login now