@@ -1,490 +1,492 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 | require 'repositories_controller' |
|
19 | require 'repositories_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class RepositoriesController; def rescue_action(e) raise e end; end |
|
22 | class RepositoriesController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class RepositoriesMercurialControllerTest < ActionController::TestCase |
|
24 | class RepositoriesMercurialControllerTest < ActionController::TestCase | |
25 | fixtures :projects, :users, :roles, :members, :member_roles, |
|
25 | fixtures :projects, :users, :roles, :members, :member_roles, | |
26 | :repositories, :enabled_modules |
|
26 | :repositories, :enabled_modules | |
27 |
|
27 | |||
28 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s |
|
28 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s | |
29 | CHAR_1_HEX = "\xc3\x9c" |
|
29 | CHAR_1_HEX = "\xc3\x9c" | |
30 | PRJ_ID = 3 |
|
30 | PRJ_ID = 3 | |
31 | NUM_REV = 29 |
|
31 | NUM_REV = 29 | |
32 |
|
32 | |||
33 | ruby19_non_utf8_pass = |
|
33 | ruby19_non_utf8_pass = | |
34 | (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') |
|
34 | (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') | |
35 |
|
35 | |||
36 | def setup |
|
36 | def setup | |
37 | @controller = RepositoriesController.new |
|
37 | @controller = RepositoriesController.new | |
38 | @request = ActionController::TestRequest.new |
|
38 | @request = ActionController::TestRequest.new | |
39 | @response = ActionController::TestResponse.new |
|
39 | @response = ActionController::TestResponse.new | |
40 | User.current = nil |
|
40 | User.current = nil | |
41 | @project = Project.find(PRJ_ID) |
|
41 | @project = Project.find(PRJ_ID) | |
42 | @repository = Repository::Mercurial.create( |
|
42 | @repository = Repository::Mercurial.create( | |
43 | :project => @project, |
|
43 | :project => @project, | |
44 | :url => REPOSITORY_PATH, |
|
44 | :url => REPOSITORY_PATH, | |
45 | :path_encoding => 'ISO-8859-1' |
|
45 | :path_encoding => 'ISO-8859-1' | |
46 | ) |
|
46 | ) | |
47 | assert @repository |
|
47 | assert @repository | |
48 | @diff_c_support = true |
|
48 | @diff_c_support = true | |
49 | @char_1 = CHAR_1_HEX.dup |
|
49 | @char_1 = CHAR_1_HEX.dup | |
50 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" |
|
50 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" | |
51 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" |
|
51 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" | |
52 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" |
|
52 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" | |
53 | if @char_1.respond_to?(:force_encoding) |
|
53 | if @char_1.respond_to?(:force_encoding) | |
54 | @char_1.force_encoding('UTF-8') |
|
54 | @char_1.force_encoding('UTF-8') | |
55 | @tag_char_1.force_encoding('UTF-8') |
|
55 | @tag_char_1.force_encoding('UTF-8') | |
56 | @branch_char_0.force_encoding('UTF-8') |
|
56 | @branch_char_0.force_encoding('UTF-8') | |
57 | @branch_char_1.force_encoding('UTF-8') |
|
57 | @branch_char_1.force_encoding('UTF-8') | |
58 | end |
|
58 | end | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | if ruby19_non_utf8_pass |
|
61 | if ruby19_non_utf8_pass | |
62 | puts "TODO: Mercurial functional test fails in Ruby 1.9 " + |
|
62 | puts "TODO: Mercurial functional test fails in Ruby 1.9 " + | |
63 | "and Encoding.default_external is not UTF-8. " + |
|
63 | "and Encoding.default_external is not UTF-8. " + | |
64 | "Current value is '#{Encoding.default_external.to_s}'" |
|
64 | "Current value is '#{Encoding.default_external.to_s}'" | |
65 | def test_fake; assert true end |
|
65 | def test_fake; assert true end | |
66 | elsif File.directory?(REPOSITORY_PATH) |
|
66 | elsif File.directory?(REPOSITORY_PATH) | |
67 | def test_show_root |
|
67 | def test_show_root | |
68 | assert_equal 0, @repository.changesets.count |
|
68 | assert_equal 0, @repository.changesets.count | |
69 | @repository.fetch_changesets |
|
69 | @repository.fetch_changesets | |
70 | @project.reload |
|
70 | @project.reload | |
71 | assert_equal NUM_REV, @repository.changesets.count |
|
71 | assert_equal NUM_REV, @repository.changesets.count | |
72 | get :show, :id => PRJ_ID |
|
72 | get :show, :id => PRJ_ID | |
73 | assert_response :success |
|
73 | assert_response :success | |
74 | assert_template 'show' |
|
74 | assert_template 'show' | |
75 | assert_not_nil assigns(:entries) |
|
75 | assert_not_nil assigns(:entries) | |
76 | assert_equal 4, assigns(:entries).size |
|
76 | assert_equal 4, assigns(:entries).size | |
77 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
77 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} | |
78 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
78 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} | |
79 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
79 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} | |
80 | assert_not_nil assigns(:changesets) |
|
80 | assert_not_nil assigns(:changesets) | |
81 | assert assigns(:changesets).size > 0 |
|
81 | assert assigns(:changesets).size > 0 | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def test_show_directory |
|
84 | def test_show_directory | |
85 | assert_equal 0, @repository.changesets.count |
|
85 | assert_equal 0, @repository.changesets.count | |
86 | @repository.fetch_changesets |
|
86 | @repository.fetch_changesets | |
87 | @project.reload |
|
87 | @project.reload | |
88 | assert_equal NUM_REV, @repository.changesets.count |
|
88 | assert_equal NUM_REV, @repository.changesets.count | |
89 | get :show, :id => PRJ_ID, :path => ['images'] |
|
89 | get :show, :id => PRJ_ID, :path => ['images'] | |
90 | assert_response :success |
|
90 | assert_response :success | |
91 | assert_template 'show' |
|
91 | assert_template 'show' | |
92 | assert_not_nil assigns(:entries) |
|
92 | assert_not_nil assigns(:entries) | |
93 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
93 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
94 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
94 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
95 | assert_not_nil entry |
|
95 | assert_not_nil entry | |
96 | assert_equal 'file', entry.kind |
|
96 | assert_equal 'file', entry.kind | |
97 | assert_equal 'images/edit.png', entry.path |
|
97 | assert_equal 'images/edit.png', entry.path | |
98 | assert_not_nil assigns(:changesets) |
|
98 | assert_not_nil assigns(:changesets) | |
99 | assert assigns(:changesets).size > 0 |
|
99 | assert assigns(:changesets).size > 0 | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | def test_show_at_given_revision |
|
102 | def test_show_at_given_revision | |
103 | assert_equal 0, @repository.changesets.count |
|
103 | assert_equal 0, @repository.changesets.count | |
104 | @repository.fetch_changesets |
|
104 | @repository.fetch_changesets | |
105 | @project.reload |
|
105 | @project.reload | |
106 | assert_equal NUM_REV, @repository.changesets.count |
|
106 | assert_equal NUM_REV, @repository.changesets.count | |
107 | [0, '0', '0885933ad4f6'].each do |r1| |
|
107 | [0, '0', '0885933ad4f6'].each do |r1| | |
108 | get :show, :id => PRJ_ID, :path => ['images'], :rev => r1 |
|
108 | get :show, :id => PRJ_ID, :path => ['images'], :rev => r1 | |
109 | assert_response :success |
|
109 | assert_response :success | |
110 | assert_template 'show' |
|
110 | assert_template 'show' | |
111 | assert_not_nil assigns(:entries) |
|
111 | assert_not_nil assigns(:entries) | |
112 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
112 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |
113 | assert_not_nil assigns(:changesets) |
|
113 | assert_not_nil assigns(:changesets) | |
114 | assert assigns(:changesets).size > 0 |
|
114 | assert assigns(:changesets).size > 0 | |
115 | end |
|
115 | end | |
116 | end |
|
116 | end | |
117 |
|
117 | |||
118 | def test_show_directory_sql_escape_percent |
|
118 | def test_show_directory_sql_escape_percent | |
119 | assert_equal 0, @repository.changesets.count |
|
119 | assert_equal 0, @repository.changesets.count | |
120 | @repository.fetch_changesets |
|
120 | @repository.fetch_changesets | |
121 | @project.reload |
|
121 | @project.reload | |
122 | assert_equal NUM_REV, @repository.changesets.count |
|
122 | assert_equal NUM_REV, @repository.changesets.count | |
123 | [13, '13', '3a330eb32958'].each do |r1| |
|
123 | [13, '13', '3a330eb32958'].each do |r1| | |
124 | get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'], |
|
124 | get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'], | |
125 | :rev => r1 |
|
125 | :rev => r1 | |
126 | assert_response :success |
|
126 | assert_response :success | |
127 | assert_template 'show' |
|
127 | assert_template 'show' | |
128 |
|
128 | |||
129 | assert_not_nil assigns(:entries) |
|
129 | assert_not_nil assigns(:entries) | |
130 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], |
|
130 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], | |
131 | assigns(:entries).collect(&:name) |
|
131 | assigns(:entries).collect(&:name) | |
132 | changesets = assigns(:changesets) |
|
132 | changesets = assigns(:changesets) | |
133 | assert_not_nil changesets |
|
133 | assert_not_nil changesets | |
134 | assert assigns(:changesets).size > 0 |
|
134 | assert assigns(:changesets).size > 0 | |
135 | assert_equal %w(13 11 10 9), changesets.collect(&:revision) |
|
135 | assert_equal %w(13 11 10 9), changesets.collect(&:revision) | |
136 | end |
|
136 | end | |
137 | end |
|
137 | end | |
138 |
|
138 | |||
139 | def test_show_directory_latin_1_path |
|
139 | def test_show_directory_latin_1_path | |
|
140 | assert_equal 0, @repository.changesets.count | |||
140 | @repository.fetch_changesets |
|
141 | @repository.fetch_changesets | |
141 |
@ |
|
142 | @project.reload | |
|
143 | assert_equal NUM_REV, @repository.changesets.count | |||
142 | [21, '21', 'adf805632193'].each do |r1| |
|
144 | [21, '21', 'adf805632193'].each do |r1| | |
143 | get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1 |
|
145 | get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1 | |
144 | assert_response :success |
|
146 | assert_response :success | |
145 | assert_template 'show' |
|
147 | assert_template 'show' | |
146 |
|
148 | |||
147 | assert_not_nil assigns(:entries) |
|
149 | assert_not_nil assigns(:entries) | |
148 | assert_equal ["make-latin-1-file.rb", |
|
150 | assert_equal ["make-latin-1-file.rb", | |
149 | "test-#{@char_1}-1.txt", |
|
151 | "test-#{@char_1}-1.txt", | |
150 | "test-#{@char_1}-2.txt", |
|
152 | "test-#{@char_1}-2.txt", | |
151 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) |
|
153 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) | |
152 | changesets = assigns(:changesets) |
|
154 | changesets = assigns(:changesets) | |
153 | assert_not_nil changesets |
|
155 | assert_not_nil changesets | |
154 | assert_equal %w(21 20 19 18 17), changesets.collect(&:revision) |
|
156 | assert_equal %w(21 20 19 18 17), changesets.collect(&:revision) | |
155 | end |
|
157 | end | |
156 | end |
|
158 | end | |
157 |
|
159 | |||
158 | def test_show_branch |
|
160 | def test_show_branch | |
159 | @repository.fetch_changesets |
|
161 | @repository.fetch_changesets | |
160 | @repository.reload |
|
162 | @repository.reload | |
161 | [ |
|
163 | [ | |
162 | 'default', |
|
164 | 'default', | |
163 | @branch_char_1, |
|
165 | @branch_char_1, | |
164 | 'branch (1)[2]&,%.-3_4', |
|
166 | 'branch (1)[2]&,%.-3_4', | |
165 | @branch_char_0, |
|
167 | @branch_char_0, | |
166 | 'test_branch.latin-1', |
|
168 | 'test_branch.latin-1', | |
167 | 'test-branch-00', |
|
169 | 'test-branch-00', | |
168 | ].each do |bra| |
|
170 | ].each do |bra| | |
169 | get :show, :id => PRJ_ID, :rev => bra |
|
171 | get :show, :id => PRJ_ID, :rev => bra | |
170 | assert_response :success |
|
172 | assert_response :success | |
171 | assert_template 'show' |
|
173 | assert_template 'show' | |
172 | assert_not_nil assigns(:entries) |
|
174 | assert_not_nil assigns(:entries) | |
173 | assert assigns(:entries).size > 0 |
|
175 | assert assigns(:entries).size > 0 | |
174 | assert_not_nil assigns(:changesets) |
|
176 | assert_not_nil assigns(:changesets) | |
175 | assert assigns(:changesets).size > 0 |
|
177 | assert assigns(:changesets).size > 0 | |
176 | end |
|
178 | end | |
177 | end |
|
179 | end | |
178 |
|
180 | |||
179 | def test_show_tag |
|
181 | def test_show_tag | |
180 | @repository.fetch_changesets |
|
182 | @repository.fetch_changesets | |
181 | @repository.reload |
|
183 | @repository.reload | |
182 | [ |
|
184 | [ | |
183 | @tag_char_1, |
|
185 | @tag_char_1, | |
184 | 'tag_test.00', |
|
186 | 'tag_test.00', | |
185 | 'tag-init-revision' |
|
187 | 'tag-init-revision' | |
186 | ].each do |tag| |
|
188 | ].each do |tag| | |
187 | get :show, :id => PRJ_ID, :rev => tag |
|
189 | get :show, :id => PRJ_ID, :rev => tag | |
188 | assert_response :success |
|
190 | assert_response :success | |
189 | assert_template 'show' |
|
191 | assert_template 'show' | |
190 | assert_not_nil assigns(:entries) |
|
192 | assert_not_nil assigns(:entries) | |
191 | assert assigns(:entries).size > 0 |
|
193 | assert assigns(:entries).size > 0 | |
192 | assert_not_nil assigns(:changesets) |
|
194 | assert_not_nil assigns(:changesets) | |
193 | assert assigns(:changesets).size > 0 |
|
195 | assert assigns(:changesets).size > 0 | |
194 | end |
|
196 | end | |
195 | end |
|
197 | end | |
196 |
|
198 | |||
197 | def test_changes |
|
199 | def test_changes | |
198 | get :changes, :id => PRJ_ID, :path => ['images', 'edit.png'] |
|
200 | get :changes, :id => PRJ_ID, :path => ['images', 'edit.png'] | |
199 | assert_response :success |
|
201 | assert_response :success | |
200 | assert_template 'changes' |
|
202 | assert_template 'changes' | |
201 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
203 | assert_tag :tag => 'h2', :content => 'edit.png' | |
202 | end |
|
204 | end | |
203 |
|
205 | |||
204 | def test_entry_show |
|
206 | def test_entry_show | |
205 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
|
207 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] | |
206 | assert_response :success |
|
208 | assert_response :success | |
207 | assert_template 'entry' |
|
209 | assert_template 'entry' | |
208 | # Line 10 |
|
210 | # Line 10 | |
209 | assert_tag :tag => 'th', |
|
211 | assert_tag :tag => 'th', | |
210 | :content => '10', |
|
212 | :content => '10', | |
211 | :attributes => { :class => 'line-num' }, |
|
213 | :attributes => { :class => 'line-num' }, | |
212 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
|
214 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } | |
213 | end |
|
215 | end | |
214 |
|
216 | |||
215 | def test_entry_show_latin_1_path |
|
217 | def test_entry_show_latin_1_path | |
216 | [21, '21', 'adf805632193'].each do |r1| |
|
218 | [21, '21', 'adf805632193'].each do |r1| | |
217 | get :entry, :id => PRJ_ID, |
|
219 | get :entry, :id => PRJ_ID, | |
218 | :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 |
|
220 | :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 | |
219 | assert_response :success |
|
221 | assert_response :success | |
220 | assert_template 'entry' |
|
222 | assert_template 'entry' | |
221 | assert_tag :tag => 'th', |
|
223 | assert_tag :tag => 'th', | |
222 | :content => '1', |
|
224 | :content => '1', | |
223 | :attributes => { :class => 'line-num' }, |
|
225 | :attributes => { :class => 'line-num' }, | |
224 | :sibling => { :tag => 'td', |
|
226 | :sibling => { :tag => 'td', | |
225 | :content => /Mercurial is a distributed version control system/ } |
|
227 | :content => /Mercurial is a distributed version control system/ } | |
226 | end |
|
228 | end | |
227 | end |
|
229 | end | |
228 |
|
230 | |||
229 | def test_entry_show_latin_1_contents |
|
231 | def test_entry_show_latin_1_contents | |
230 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
232 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
231 | [27, '27', '7bbf4c738e71'].each do |r1| |
|
233 | [27, '27', '7bbf4c738e71'].each do |r1| | |
232 | get :entry, :id => PRJ_ID, |
|
234 | get :entry, :id => PRJ_ID, | |
233 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 |
|
235 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 | |
234 | assert_response :success |
|
236 | assert_response :success | |
235 | assert_template 'entry' |
|
237 | assert_template 'entry' | |
236 | assert_tag :tag => 'th', |
|
238 | assert_tag :tag => 'th', | |
237 | :content => '1', |
|
239 | :content => '1', | |
238 | :attributes => { :class => 'line-num' }, |
|
240 | :attributes => { :class => 'line-num' }, | |
239 | :sibling => { :tag => 'td', |
|
241 | :sibling => { :tag => 'td', | |
240 | :content => /test-#{@char_1}.txt/ } |
|
242 | :content => /test-#{@char_1}.txt/ } | |
241 | end |
|
243 | end | |
242 | end |
|
244 | end | |
243 | end |
|
245 | end | |
244 |
|
246 | |||
245 | def test_entry_download |
|
247 | def test_entry_download | |
246 | get :entry, :id => PRJ_ID, |
|
248 | get :entry, :id => PRJ_ID, | |
247 | :path => ['sources', 'watchers_controller.rb'], :format => 'raw' |
|
249 | :path => ['sources', 'watchers_controller.rb'], :format => 'raw' | |
248 | assert_response :success |
|
250 | assert_response :success | |
249 | # File content |
|
251 | # File content | |
250 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
|
252 | assert @response.body.include?('WITHOUT ANY WARRANTY') | |
251 | end |
|
253 | end | |
252 |
|
254 | |||
253 | def test_entry_binary_force_download |
|
255 | def test_entry_binary_force_download | |
254 | get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png'] |
|
256 | get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png'] | |
255 | assert_response :success |
|
257 | assert_response :success | |
256 | assert_equal 'image/png', @response.content_type |
|
258 | assert_equal 'image/png', @response.content_type | |
257 | end |
|
259 | end | |
258 |
|
260 | |||
259 | def test_directory_entry |
|
261 | def test_directory_entry | |
260 | get :entry, :id => PRJ_ID, :path => ['sources'] |
|
262 | get :entry, :id => PRJ_ID, :path => ['sources'] | |
261 | assert_response :success |
|
263 | assert_response :success | |
262 | assert_template 'show' |
|
264 | assert_template 'show' | |
263 | assert_not_nil assigns(:entry) |
|
265 | assert_not_nil assigns(:entry) | |
264 | assert_equal 'sources', assigns(:entry).name |
|
266 | assert_equal 'sources', assigns(:entry).name | |
265 | end |
|
267 | end | |
266 |
|
268 | |||
267 | def test_diff |
|
269 | def test_diff | |
268 | @repository.fetch_changesets |
|
270 | @repository.fetch_changesets | |
269 | @repository.reload |
|
271 | @repository.reload | |
270 | [4, '4', 'def6d2f1254a'].each do |r1| |
|
272 | [4, '4', 'def6d2f1254a'].each do |r1| | |
271 | # Full diff of changeset 4 |
|
273 | # Full diff of changeset 4 | |
272 | ['inline', 'sbs'].each do |dt| |
|
274 | ['inline', 'sbs'].each do |dt| | |
273 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
275 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt | |
274 | assert_response :success |
|
276 | assert_response :success | |
275 | assert_template 'diff' |
|
277 | assert_template 'diff' | |
276 | if @diff_c_support |
|
278 | if @diff_c_support | |
277 | # Line 22 removed |
|
279 | # Line 22 removed | |
278 | assert_tag :tag => 'th', |
|
280 | assert_tag :tag => 'th', | |
279 | :content => '22', |
|
281 | :content => '22', | |
280 | :sibling => { :tag => 'td', |
|
282 | :sibling => { :tag => 'td', | |
281 | :attributes => { :class => /diff_out/ }, |
|
283 | :attributes => { :class => /diff_out/ }, | |
282 | :content => /def remove/ } |
|
284 | :content => /def remove/ } | |
283 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ |
|
285 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ | |
284 | end |
|
286 | end | |
285 | end |
|
287 | end | |
286 | end |
|
288 | end | |
287 | end |
|
289 | end | |
288 |
|
290 | |||
289 | def test_diff_two_revs |
|
291 | def test_diff_two_revs | |
290 | @repository.fetch_changesets |
|
292 | @repository.fetch_changesets | |
291 | @repository.reload |
|
293 | @repository.reload | |
292 | [2, '400bb8672109', '400', 400].each do |r1| |
|
294 | [2, '400bb8672109', '400', 400].each do |r1| | |
293 | [4, 'def6d2f1254a'].each do |r2| |
|
295 | [4, 'def6d2f1254a'].each do |r2| | |
294 | ['inline', 'sbs'].each do |dt| |
|
296 | ['inline', 'sbs'].each do |dt| | |
295 | get :diff, |
|
297 | get :diff, | |
296 | :id => PRJ_ID, |
|
298 | :id => PRJ_ID, | |
297 | :rev => r1, |
|
299 | :rev => r1, | |
298 | :rev_to => r2, |
|
300 | :rev_to => r2, | |
299 | :type => dt |
|
301 | :type => dt | |
300 | assert_response :success |
|
302 | assert_response :success | |
301 | assert_template 'diff' |
|
303 | assert_template 'diff' | |
302 | diff = assigns(:diff) |
|
304 | diff = assigns(:diff) | |
303 | assert_not_nil diff |
|
305 | assert_not_nil diff | |
304 | assert_tag :tag => 'h2', |
|
306 | assert_tag :tag => 'h2', | |
305 | :content => /4:def6d2f1254a 2:400bb8672109/ |
|
307 | :content => /4:def6d2f1254a 2:400bb8672109/ | |
306 | end |
|
308 | end | |
307 | end |
|
309 | end | |
308 | end |
|
310 | end | |
309 | end |
|
311 | end | |
310 |
|
312 | |||
311 | def test_diff_latin_1_path |
|
313 | def test_diff_latin_1_path | |
312 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
314 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
313 | [21, 'adf805632193'].each do |r1| |
|
315 | [21, 'adf805632193'].each do |r1| | |
314 | ['inline', 'sbs'].each do |dt| |
|
316 | ['inline', 'sbs'].each do |dt| | |
315 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
317 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt | |
316 | assert_response :success |
|
318 | assert_response :success | |
317 | assert_template 'diff' |
|
319 | assert_template 'diff' | |
318 | assert_tag :tag => 'thead', |
|
320 | assert_tag :tag => 'thead', | |
319 | :descendant => { |
|
321 | :descendant => { | |
320 | :tag => 'th', |
|
322 | :tag => 'th', | |
321 | :attributes => { :class => 'filename' } , |
|
323 | :attributes => { :class => 'filename' } , | |
322 | :content => /latin-1-dir\/test-#{@char_1}-2.txt/ , |
|
324 | :content => /latin-1-dir\/test-#{@char_1}-2.txt/ , | |
323 | }, |
|
325 | }, | |
324 | :sibling => { |
|
326 | :sibling => { | |
325 | :tag => 'tbody', |
|
327 | :tag => 'tbody', | |
326 | :descendant => { |
|
328 | :descendant => { | |
327 | :tag => 'td', |
|
329 | :tag => 'td', | |
328 | :attributes => { :class => /diff_in/ }, |
|
330 | :attributes => { :class => /diff_in/ }, | |
329 | :content => /It is written in Python/ |
|
331 | :content => /It is written in Python/ | |
330 | } |
|
332 | } | |
331 | } |
|
333 | } | |
332 | end |
|
334 | end | |
333 | end |
|
335 | end | |
334 | end |
|
336 | end | |
335 | end |
|
337 | end | |
336 |
|
338 | |||
337 | def test_annotate |
|
339 | def test_annotate | |
338 | get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
|
340 | get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] | |
339 | assert_response :success |
|
341 | assert_response :success | |
340 | assert_template 'annotate' |
|
342 | assert_template 'annotate' | |
341 | # Line 23, revision 4:def6d2f1254a |
|
343 | # Line 23, revision 4:def6d2f1254a | |
342 | assert_tag :tag => 'th', |
|
344 | assert_tag :tag => 'th', | |
343 | :content => '23', |
|
345 | :content => '23', | |
344 | :attributes => { :class => 'line-num' }, |
|
346 | :attributes => { :class => 'line-num' }, | |
345 | :sibling => |
|
347 | :sibling => | |
346 | { |
|
348 | { | |
347 | :tag => 'td', |
|
349 | :tag => 'td', | |
348 | :attributes => { :class => 'revision' }, |
|
350 | :attributes => { :class => 'revision' }, | |
349 | :child => { :tag => 'a', :content => '4:def6d2f1254a' } |
|
351 | :child => { :tag => 'a', :content => '4:def6d2f1254a' } | |
350 | } |
|
352 | } | |
351 | assert_tag :tag => 'th', |
|
353 | assert_tag :tag => 'th', | |
352 | :content => '23', |
|
354 | :content => '23', | |
353 | :attributes => { :class => 'line-num' }, |
|
355 | :attributes => { :class => 'line-num' }, | |
354 | :sibling => |
|
356 | :sibling => | |
355 | { |
|
357 | { | |
356 | :tag => 'td' , |
|
358 | :tag => 'td' , | |
357 | :content => 'jsmith' , |
|
359 | :content => 'jsmith' , | |
358 | :attributes => { :class => 'author' }, |
|
360 | :attributes => { :class => 'author' }, | |
359 | } |
|
361 | } | |
360 | assert_tag :tag => 'th', |
|
362 | assert_tag :tag => 'th', | |
361 | :content => '23', |
|
363 | :content => '23', | |
362 | :attributes => { :class => 'line-num' }, |
|
364 | :attributes => { :class => 'line-num' }, | |
363 | :sibling => { :tag => 'td', :content => /watcher =/ } |
|
365 | :sibling => { :tag => 'td', :content => /watcher =/ } | |
364 | end |
|
366 | end | |
365 |
|
367 | |||
366 | def test_annotate_not_in_tip |
|
368 | def test_annotate_not_in_tip | |
367 | @repository.fetch_changesets |
|
369 | @repository.fetch_changesets | |
368 | @repository.reload |
|
370 | @repository.reload | |
369 | assert @repository.changesets.size > 0 |
|
371 | assert @repository.changesets.size > 0 | |
370 |
|
372 | |||
371 | get :annotate, :id => PRJ_ID, |
|
373 | get :annotate, :id => PRJ_ID, | |
372 | :path => ['sources', 'welcome_controller.rb'] |
|
374 | :path => ['sources', 'welcome_controller.rb'] | |
373 | assert_response 404 |
|
375 | assert_response 404 | |
374 | assert_error_tag :content => /was not found/ |
|
376 | assert_error_tag :content => /was not found/ | |
375 | end |
|
377 | end | |
376 |
|
378 | |||
377 | def test_annotate_at_given_revision |
|
379 | def test_annotate_at_given_revision | |
378 | @repository.fetch_changesets |
|
380 | @repository.fetch_changesets | |
379 | @repository.reload |
|
381 | @repository.reload | |
380 | [2, '400bb8672109', '400', 400].each do |r1| |
|
382 | [2, '400bb8672109', '400', 400].each do |r1| | |
381 | get :annotate, :id => PRJ_ID, :rev => r1, |
|
383 | get :annotate, :id => PRJ_ID, :rev => r1, | |
382 | :path => ['sources', 'watchers_controller.rb'] |
|
384 | :path => ['sources', 'watchers_controller.rb'] | |
383 | assert_response :success |
|
385 | assert_response :success | |
384 | assert_template 'annotate' |
|
386 | assert_template 'annotate' | |
385 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ |
|
387 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ | |
386 | end |
|
388 | end | |
387 | end |
|
389 | end | |
388 |
|
390 | |||
389 | def test_annotate_latin_1_path |
|
391 | def test_annotate_latin_1_path | |
390 | [21, '21', 'adf805632193'].each do |r1| |
|
392 | [21, '21', 'adf805632193'].each do |r1| | |
391 | get :annotate, :id => PRJ_ID, |
|
393 | get :annotate, :id => PRJ_ID, | |
392 | :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 |
|
394 | :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 | |
393 | assert_response :success |
|
395 | assert_response :success | |
394 | assert_template 'annotate' |
|
396 | assert_template 'annotate' | |
395 | assert_tag :tag => 'th', |
|
397 | assert_tag :tag => 'th', | |
396 | :content => '1', |
|
398 | :content => '1', | |
397 | :attributes => { :class => 'line-num' }, |
|
399 | :attributes => { :class => 'line-num' }, | |
398 | :sibling => |
|
400 | :sibling => | |
399 | { |
|
401 | { | |
400 | :tag => 'td', |
|
402 | :tag => 'td', | |
401 | :attributes => { :class => 'revision' }, |
|
403 | :attributes => { :class => 'revision' }, | |
402 | :child => { :tag => 'a', :content => '20:709858aafd1b' } |
|
404 | :child => { :tag => 'a', :content => '20:709858aafd1b' } | |
403 | } |
|
405 | } | |
404 | assert_tag :tag => 'th', |
|
406 | assert_tag :tag => 'th', | |
405 | :content => '1', |
|
407 | :content => '1', | |
406 | :attributes => { :class => 'line-num' }, |
|
408 | :attributes => { :class => 'line-num' }, | |
407 | :sibling => |
|
409 | :sibling => | |
408 | { |
|
410 | { | |
409 | :tag => 'td' , |
|
411 | :tag => 'td' , | |
410 | :content => 'jsmith' , |
|
412 | :content => 'jsmith' , | |
411 | :attributes => { :class => 'author' }, |
|
413 | :attributes => { :class => 'author' }, | |
412 | } |
|
414 | } | |
413 | assert_tag :tag => 'th', |
|
415 | assert_tag :tag => 'th', | |
414 | :content => '1', |
|
416 | :content => '1', | |
415 | :attributes => { :class => 'line-num' }, |
|
417 | :attributes => { :class => 'line-num' }, | |
416 | :sibling => { :tag => 'td', |
|
418 | :sibling => { :tag => 'td', | |
417 | :content => /Mercurial is a distributed version control system/ } |
|
419 | :content => /Mercurial is a distributed version control system/ } | |
418 |
|
420 | |||
419 | end |
|
421 | end | |
420 | end |
|
422 | end | |
421 |
|
423 | |||
422 | def test_annotate_latin_1_contents |
|
424 | def test_annotate_latin_1_contents | |
423 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
425 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
424 | [27, '7bbf4c738e71'].each do |r1| |
|
426 | [27, '7bbf4c738e71'].each do |r1| | |
425 | get :annotate, :id => PRJ_ID, |
|
427 | get :annotate, :id => PRJ_ID, | |
426 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 |
|
428 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 | |
427 | assert_tag :tag => 'th', |
|
429 | assert_tag :tag => 'th', | |
428 | :content => '1', |
|
430 | :content => '1', | |
429 | :attributes => { :class => 'line-num' }, |
|
431 | :attributes => { :class => 'line-num' }, | |
430 | :sibling => { :tag => 'td', |
|
432 | :sibling => { :tag => 'td', | |
431 | :content => /test-#{@char_1}.txt/ } |
|
433 | :content => /test-#{@char_1}.txt/ } | |
432 | end |
|
434 | end | |
433 | end |
|
435 | end | |
434 | end |
|
436 | end | |
435 |
|
437 | |||
436 | def test_empty_revision |
|
438 | def test_empty_revision | |
437 | @repository.fetch_changesets |
|
439 | @repository.fetch_changesets | |
438 | @repository.reload |
|
440 | @repository.reload | |
439 | ['', ' ', nil].each do |r| |
|
441 | ['', ' ', nil].each do |r| | |
440 | get :revision, :id => PRJ_ID, :rev => r |
|
442 | get :revision, :id => PRJ_ID, :rev => r | |
441 | assert_response 404 |
|
443 | assert_response 404 | |
442 | assert_error_tag :content => /was not found/ |
|
444 | assert_error_tag :content => /was not found/ | |
443 | end |
|
445 | end | |
444 | end |
|
446 | end | |
445 |
|
447 | |||
446 | def test_destroy_valid_repository |
|
448 | def test_destroy_valid_repository | |
447 | @request.session[:user_id] = 1 # admin |
|
449 | @request.session[:user_id] = 1 # admin | |
448 | assert_equal 0, @repository.changesets.count |
|
450 | assert_equal 0, @repository.changesets.count | |
449 | @repository.fetch_changesets |
|
451 | @repository.fetch_changesets | |
450 | @project.reload |
|
452 | @project.reload | |
451 | assert_equal NUM_REV, @repository.changesets.count |
|
453 | assert_equal NUM_REV, @repository.changesets.count | |
452 |
|
454 | |||
453 | get :destroy, :id => PRJ_ID |
|
455 | get :destroy, :id => PRJ_ID | |
454 | assert_response 302 |
|
456 | assert_response 302 | |
455 | @project.reload |
|
457 | @project.reload | |
456 | assert_nil @project.repository |
|
458 | assert_nil @project.repository | |
457 | end |
|
459 | end | |
458 |
|
460 | |||
459 | def test_destroy_invalid_repository |
|
461 | def test_destroy_invalid_repository | |
460 | @request.session[:user_id] = 1 # admin |
|
462 | @request.session[:user_id] = 1 # admin | |
461 | assert_equal 0, @repository.changesets.count |
|
463 | assert_equal 0, @repository.changesets.count | |
462 | @repository.fetch_changesets |
|
464 | @repository.fetch_changesets | |
463 | @project.reload |
|
465 | @project.reload | |
464 | assert_equal NUM_REV, @repository.changesets.count |
|
466 | assert_equal NUM_REV, @repository.changesets.count | |
465 |
|
467 | |||
466 | get :destroy, :id => PRJ_ID |
|
468 | get :destroy, :id => PRJ_ID | |
467 | assert_response 302 |
|
469 | assert_response 302 | |
468 | @project.reload |
|
470 | @project.reload | |
469 | assert_nil @project.repository |
|
471 | assert_nil @project.repository | |
470 |
|
472 | |||
471 | @repository = Repository::Mercurial.create( |
|
473 | @repository = Repository::Mercurial.create( | |
472 | :project => Project.find(PRJ_ID), |
|
474 | :project => Project.find(PRJ_ID), | |
473 | :url => "/invalid", |
|
475 | :url => "/invalid", | |
474 | :path_encoding => 'ISO-8859-1' |
|
476 | :path_encoding => 'ISO-8859-1' | |
475 | ) |
|
477 | ) | |
476 | assert @repository |
|
478 | assert @repository | |
477 | @repository.fetch_changesets |
|
479 | @repository.fetch_changesets | |
478 | @project.reload |
|
480 | @project.reload | |
479 | assert_equal 0, @repository.changesets.count |
|
481 | assert_equal 0, @repository.changesets.count | |
480 |
|
482 | |||
481 | get :destroy, :id => PRJ_ID |
|
483 | get :destroy, :id => PRJ_ID | |
482 | assert_response 302 |
|
484 | assert_response 302 | |
483 | @project.reload |
|
485 | @project.reload | |
484 | assert_nil @project.repository |
|
486 | assert_nil @project.repository | |
485 | end |
|
487 | end | |
486 | else |
|
488 | else | |
487 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" |
|
489 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" | |
488 | def test_fake; assert true end |
|
490 | def test_fake; assert true end | |
489 | end |
|
491 | end | |
490 | end |
|
492 | end |
General Comments 0
You need to be logged in to leave comments.
Login now