@@ -1,484 +1,486 | |||||
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 | @repository.fetch_changesets |
|
104 | @repository.fetch_changesets | |
104 |
@ |
|
105 | @project.reload | |
|
106 | assert_equal NUM_REV, @repository.changesets.count | |||
105 | [0, '0', '0885933ad4f6'].each do |r1| |
|
107 | [0, '0', '0885933ad4f6'].each do |r1| | |
106 | get :show, :id => PRJ_ID, :path => ['images'], :rev => r1 |
|
108 | get :show, :id => PRJ_ID, :path => ['images'], :rev => r1 | |
107 | assert_response :success |
|
109 | assert_response :success | |
108 | assert_template 'show' |
|
110 | assert_template 'show' | |
109 | assert_not_nil assigns(:entries) |
|
111 | assert_not_nil assigns(:entries) | |
110 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
112 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |
111 | assert_not_nil assigns(:changesets) |
|
113 | assert_not_nil assigns(:changesets) | |
112 | assert assigns(:changesets).size > 0 |
|
114 | assert assigns(:changesets).size > 0 | |
113 | end |
|
115 | end | |
114 | end |
|
116 | end | |
115 |
|
117 | |||
116 | def test_show_directory_sql_escape_percent |
|
118 | def test_show_directory_sql_escape_percent | |
117 | @repository.fetch_changesets |
|
119 | @repository.fetch_changesets | |
118 | @repository.reload |
|
120 | @repository.reload | |
119 | [13, '13', '3a330eb32958'].each do |r1| |
|
121 | [13, '13', '3a330eb32958'].each do |r1| | |
120 | get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'], |
|
122 | get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'], | |
121 | :rev => r1 |
|
123 | :rev => r1 | |
122 | assert_response :success |
|
124 | assert_response :success | |
123 | assert_template 'show' |
|
125 | assert_template 'show' | |
124 |
|
126 | |||
125 | assert_not_nil assigns(:entries) |
|
127 | assert_not_nil assigns(:entries) | |
126 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], |
|
128 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], | |
127 | assigns(:entries).collect(&:name) |
|
129 | assigns(:entries).collect(&:name) | |
128 | changesets = assigns(:changesets) |
|
130 | changesets = assigns(:changesets) | |
129 | assert_not_nil changesets |
|
131 | assert_not_nil changesets | |
130 | assert assigns(:changesets).size > 0 |
|
132 | assert assigns(:changesets).size > 0 | |
131 | assert_equal %w(13 11 10 9), changesets.collect(&:revision) |
|
133 | assert_equal %w(13 11 10 9), changesets.collect(&:revision) | |
132 | end |
|
134 | end | |
133 | end |
|
135 | end | |
134 |
|
136 | |||
135 | def test_show_directory_latin_1_path |
|
137 | def test_show_directory_latin_1_path | |
136 | @repository.fetch_changesets |
|
138 | @repository.fetch_changesets | |
137 | @repository.reload |
|
139 | @repository.reload | |
138 | [21, '21', 'adf805632193'].each do |r1| |
|
140 | [21, '21', 'adf805632193'].each do |r1| | |
139 | get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1 |
|
141 | get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1 | |
140 | assert_response :success |
|
142 | assert_response :success | |
141 | assert_template 'show' |
|
143 | assert_template 'show' | |
142 |
|
144 | |||
143 | assert_not_nil assigns(:entries) |
|
145 | assert_not_nil assigns(:entries) | |
144 | assert_equal ["make-latin-1-file.rb", |
|
146 | assert_equal ["make-latin-1-file.rb", | |
145 | "test-#{@char_1}-1.txt", |
|
147 | "test-#{@char_1}-1.txt", | |
146 | "test-#{@char_1}-2.txt", |
|
148 | "test-#{@char_1}-2.txt", | |
147 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) |
|
149 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) | |
148 | changesets = assigns(:changesets) |
|
150 | changesets = assigns(:changesets) | |
149 | assert_not_nil changesets |
|
151 | assert_not_nil changesets | |
150 | assert_equal %w(21 20 19 18 17), changesets.collect(&:revision) |
|
152 | assert_equal %w(21 20 19 18 17), changesets.collect(&:revision) | |
151 | end |
|
153 | end | |
152 | end |
|
154 | end | |
153 |
|
155 | |||
154 | def test_show_branch |
|
156 | def test_show_branch | |
155 | @repository.fetch_changesets |
|
157 | @repository.fetch_changesets | |
156 | @repository.reload |
|
158 | @repository.reload | |
157 | [ |
|
159 | [ | |
158 | 'default', |
|
160 | 'default', | |
159 | @branch_char_1, |
|
161 | @branch_char_1, | |
160 | 'branch (1)[2]&,%.-3_4', |
|
162 | 'branch (1)[2]&,%.-3_4', | |
161 | @branch_char_0, |
|
163 | @branch_char_0, | |
162 | 'test_branch.latin-1', |
|
164 | 'test_branch.latin-1', | |
163 | 'test-branch-00', |
|
165 | 'test-branch-00', | |
164 | ].each do |bra| |
|
166 | ].each do |bra| | |
165 | get :show, :id => PRJ_ID, :rev => bra |
|
167 | get :show, :id => PRJ_ID, :rev => bra | |
166 | assert_response :success |
|
168 | assert_response :success | |
167 | assert_template 'show' |
|
169 | assert_template 'show' | |
168 | assert_not_nil assigns(:entries) |
|
170 | assert_not_nil assigns(:entries) | |
169 | assert assigns(:entries).size > 0 |
|
171 | assert assigns(:entries).size > 0 | |
170 | assert_not_nil assigns(:changesets) |
|
172 | assert_not_nil assigns(:changesets) | |
171 | assert assigns(:changesets).size > 0 |
|
173 | assert assigns(:changesets).size > 0 | |
172 | end |
|
174 | end | |
173 | end |
|
175 | end | |
174 |
|
176 | |||
175 | def test_show_tag |
|
177 | def test_show_tag | |
176 | @repository.fetch_changesets |
|
178 | @repository.fetch_changesets | |
177 | @repository.reload |
|
179 | @repository.reload | |
178 | [ |
|
180 | [ | |
179 | @tag_char_1, |
|
181 | @tag_char_1, | |
180 | 'tag_test.00', |
|
182 | 'tag_test.00', | |
181 | 'tag-init-revision' |
|
183 | 'tag-init-revision' | |
182 | ].each do |tag| |
|
184 | ].each do |tag| | |
183 | get :show, :id => PRJ_ID, :rev => tag |
|
185 | get :show, :id => PRJ_ID, :rev => tag | |
184 | assert_response :success |
|
186 | assert_response :success | |
185 | assert_template 'show' |
|
187 | assert_template 'show' | |
186 | assert_not_nil assigns(:entries) |
|
188 | assert_not_nil assigns(:entries) | |
187 | assert assigns(:entries).size > 0 |
|
189 | assert assigns(:entries).size > 0 | |
188 | assert_not_nil assigns(:changesets) |
|
190 | assert_not_nil assigns(:changesets) | |
189 | assert assigns(:changesets).size > 0 |
|
191 | assert assigns(:changesets).size > 0 | |
190 | end |
|
192 | end | |
191 | end |
|
193 | end | |
192 |
|
194 | |||
193 | def test_changes |
|
195 | def test_changes | |
194 | get :changes, :id => PRJ_ID, :path => ['images', 'edit.png'] |
|
196 | get :changes, :id => PRJ_ID, :path => ['images', 'edit.png'] | |
195 | assert_response :success |
|
197 | assert_response :success | |
196 | assert_template 'changes' |
|
198 | assert_template 'changes' | |
197 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
199 | assert_tag :tag => 'h2', :content => 'edit.png' | |
198 | end |
|
200 | end | |
199 |
|
201 | |||
200 | def test_entry_show |
|
202 | def test_entry_show | |
201 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
|
203 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] | |
202 | assert_response :success |
|
204 | assert_response :success | |
203 | assert_template 'entry' |
|
205 | assert_template 'entry' | |
204 | # Line 10 |
|
206 | # Line 10 | |
205 | assert_tag :tag => 'th', |
|
207 | assert_tag :tag => 'th', | |
206 | :content => '10', |
|
208 | :content => '10', | |
207 | :attributes => { :class => 'line-num' }, |
|
209 | :attributes => { :class => 'line-num' }, | |
208 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
|
210 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } | |
209 | end |
|
211 | end | |
210 |
|
212 | |||
211 | def test_entry_show_latin_1_path |
|
213 | def test_entry_show_latin_1_path | |
212 | [21, '21', 'adf805632193'].each do |r1| |
|
214 | [21, '21', 'adf805632193'].each do |r1| | |
213 | get :entry, :id => PRJ_ID, |
|
215 | get :entry, :id => PRJ_ID, | |
214 | :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 |
|
216 | :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 | |
215 | assert_response :success |
|
217 | assert_response :success | |
216 | assert_template 'entry' |
|
218 | assert_template 'entry' | |
217 | assert_tag :tag => 'th', |
|
219 | assert_tag :tag => 'th', | |
218 | :content => '1', |
|
220 | :content => '1', | |
219 | :attributes => { :class => 'line-num' }, |
|
221 | :attributes => { :class => 'line-num' }, | |
220 | :sibling => { :tag => 'td', |
|
222 | :sibling => { :tag => 'td', | |
221 | :content => /Mercurial is a distributed version control system/ } |
|
223 | :content => /Mercurial is a distributed version control system/ } | |
222 | end |
|
224 | end | |
223 | end |
|
225 | end | |
224 |
|
226 | |||
225 | def test_entry_show_latin_1_contents |
|
227 | def test_entry_show_latin_1_contents | |
226 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
228 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
227 | [27, '27', '7bbf4c738e71'].each do |r1| |
|
229 | [27, '27', '7bbf4c738e71'].each do |r1| | |
228 | get :entry, :id => PRJ_ID, |
|
230 | get :entry, :id => PRJ_ID, | |
229 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 |
|
231 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 | |
230 | assert_response :success |
|
232 | assert_response :success | |
231 | assert_template 'entry' |
|
233 | assert_template 'entry' | |
232 | assert_tag :tag => 'th', |
|
234 | assert_tag :tag => 'th', | |
233 | :content => '1', |
|
235 | :content => '1', | |
234 | :attributes => { :class => 'line-num' }, |
|
236 | :attributes => { :class => 'line-num' }, | |
235 | :sibling => { :tag => 'td', |
|
237 | :sibling => { :tag => 'td', | |
236 | :content => /test-#{@char_1}.txt/ } |
|
238 | :content => /test-#{@char_1}.txt/ } | |
237 | end |
|
239 | end | |
238 | end |
|
240 | end | |
239 | end |
|
241 | end | |
240 |
|
242 | |||
241 | def test_entry_download |
|
243 | def test_entry_download | |
242 | get :entry, :id => PRJ_ID, |
|
244 | get :entry, :id => PRJ_ID, | |
243 | :path => ['sources', 'watchers_controller.rb'], :format => 'raw' |
|
245 | :path => ['sources', 'watchers_controller.rb'], :format => 'raw' | |
244 | assert_response :success |
|
246 | assert_response :success | |
245 | # File content |
|
247 | # File content | |
246 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
|
248 | assert @response.body.include?('WITHOUT ANY WARRANTY') | |
247 | end |
|
249 | end | |
248 |
|
250 | |||
249 | def test_entry_binary_force_download |
|
251 | def test_entry_binary_force_download | |
250 | get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png'] |
|
252 | get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png'] | |
251 | assert_response :success |
|
253 | assert_response :success | |
252 | assert_equal 'image/png', @response.content_type |
|
254 | assert_equal 'image/png', @response.content_type | |
253 | end |
|
255 | end | |
254 |
|
256 | |||
255 | def test_directory_entry |
|
257 | def test_directory_entry | |
256 | get :entry, :id => PRJ_ID, :path => ['sources'] |
|
258 | get :entry, :id => PRJ_ID, :path => ['sources'] | |
257 | assert_response :success |
|
259 | assert_response :success | |
258 | assert_template 'show' |
|
260 | assert_template 'show' | |
259 | assert_not_nil assigns(:entry) |
|
261 | assert_not_nil assigns(:entry) | |
260 | assert_equal 'sources', assigns(:entry).name |
|
262 | assert_equal 'sources', assigns(:entry).name | |
261 | end |
|
263 | end | |
262 |
|
264 | |||
263 | def test_diff |
|
265 | def test_diff | |
264 | @repository.fetch_changesets |
|
266 | @repository.fetch_changesets | |
265 | @repository.reload |
|
267 | @repository.reload | |
266 | [4, '4', 'def6d2f1254a'].each do |r1| |
|
268 | [4, '4', 'def6d2f1254a'].each do |r1| | |
267 | # Full diff of changeset 4 |
|
269 | # Full diff of changeset 4 | |
268 | ['inline', 'sbs'].each do |dt| |
|
270 | ['inline', 'sbs'].each do |dt| | |
269 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
271 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt | |
270 | assert_response :success |
|
272 | assert_response :success | |
271 | assert_template 'diff' |
|
273 | assert_template 'diff' | |
272 | if @diff_c_support |
|
274 | if @diff_c_support | |
273 | # Line 22 removed |
|
275 | # Line 22 removed | |
274 | assert_tag :tag => 'th', |
|
276 | assert_tag :tag => 'th', | |
275 | :content => '22', |
|
277 | :content => '22', | |
276 | :sibling => { :tag => 'td', |
|
278 | :sibling => { :tag => 'td', | |
277 | :attributes => { :class => /diff_out/ }, |
|
279 | :attributes => { :class => /diff_out/ }, | |
278 | :content => /def remove/ } |
|
280 | :content => /def remove/ } | |
279 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ |
|
281 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ | |
280 | end |
|
282 | end | |
281 | end |
|
283 | end | |
282 | end |
|
284 | end | |
283 | end |
|
285 | end | |
284 |
|
286 | |||
285 | def test_diff_two_revs |
|
287 | def test_diff_two_revs | |
286 | @repository.fetch_changesets |
|
288 | @repository.fetch_changesets | |
287 | @repository.reload |
|
289 | @repository.reload | |
288 | [2, '400bb8672109', '400', 400].each do |r1| |
|
290 | [2, '400bb8672109', '400', 400].each do |r1| | |
289 | [4, 'def6d2f1254a'].each do |r2| |
|
291 | [4, 'def6d2f1254a'].each do |r2| | |
290 | ['inline', 'sbs'].each do |dt| |
|
292 | ['inline', 'sbs'].each do |dt| | |
291 | get :diff, |
|
293 | get :diff, | |
292 | :id => PRJ_ID, |
|
294 | :id => PRJ_ID, | |
293 | :rev => r1, |
|
295 | :rev => r1, | |
294 | :rev_to => r2, |
|
296 | :rev_to => r2, | |
295 | :type => dt |
|
297 | :type => dt | |
296 | assert_response :success |
|
298 | assert_response :success | |
297 | assert_template 'diff' |
|
299 | assert_template 'diff' | |
298 | diff = assigns(:diff) |
|
300 | diff = assigns(:diff) | |
299 | assert_not_nil diff |
|
301 | assert_not_nil diff | |
300 | assert_tag :tag => 'h2', |
|
302 | assert_tag :tag => 'h2', | |
301 | :content => /4:def6d2f1254a 2:400bb8672109/ |
|
303 | :content => /4:def6d2f1254a 2:400bb8672109/ | |
302 | end |
|
304 | end | |
303 | end |
|
305 | end | |
304 | end |
|
306 | end | |
305 | end |
|
307 | end | |
306 |
|
308 | |||
307 | def test_diff_latin_1_path |
|
309 | def test_diff_latin_1_path | |
308 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
310 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
309 | [21, 'adf805632193'].each do |r1| |
|
311 | [21, 'adf805632193'].each do |r1| | |
310 | ['inline', 'sbs'].each do |dt| |
|
312 | ['inline', 'sbs'].each do |dt| | |
311 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
313 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt | |
312 | assert_response :success |
|
314 | assert_response :success | |
313 | assert_template 'diff' |
|
315 | assert_template 'diff' | |
314 | assert_tag :tag => 'thead', |
|
316 | assert_tag :tag => 'thead', | |
315 | :descendant => { |
|
317 | :descendant => { | |
316 | :tag => 'th', |
|
318 | :tag => 'th', | |
317 | :attributes => { :class => 'filename' } , |
|
319 | :attributes => { :class => 'filename' } , | |
318 | :content => /latin-1-dir\/test-#{@char_1}-2.txt/ , |
|
320 | :content => /latin-1-dir\/test-#{@char_1}-2.txt/ , | |
319 | }, |
|
321 | }, | |
320 | :sibling => { |
|
322 | :sibling => { | |
321 | :tag => 'tbody', |
|
323 | :tag => 'tbody', | |
322 | :descendant => { |
|
324 | :descendant => { | |
323 | :tag => 'td', |
|
325 | :tag => 'td', | |
324 | :attributes => { :class => /diff_in/ }, |
|
326 | :attributes => { :class => /diff_in/ }, | |
325 | :content => /It is written in Python/ |
|
327 | :content => /It is written in Python/ | |
326 | } |
|
328 | } | |
327 | } |
|
329 | } | |
328 | end |
|
330 | end | |
329 | end |
|
331 | end | |
330 | end |
|
332 | end | |
331 | end |
|
333 | end | |
332 |
|
334 | |||
333 | def test_annotate |
|
335 | def test_annotate | |
334 | get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
|
336 | get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] | |
335 | assert_response :success |
|
337 | assert_response :success | |
336 | assert_template 'annotate' |
|
338 | assert_template 'annotate' | |
337 | # Line 23, revision 4:def6d2f1254a |
|
339 | # Line 23, revision 4:def6d2f1254a | |
338 | assert_tag :tag => 'th', |
|
340 | assert_tag :tag => 'th', | |
339 | :content => '23', |
|
341 | :content => '23', | |
340 | :attributes => { :class => 'line-num' }, |
|
342 | :attributes => { :class => 'line-num' }, | |
341 | :sibling => |
|
343 | :sibling => | |
342 | { |
|
344 | { | |
343 | :tag => 'td', |
|
345 | :tag => 'td', | |
344 | :attributes => { :class => 'revision' }, |
|
346 | :attributes => { :class => 'revision' }, | |
345 | :child => { :tag => 'a', :content => '4:def6d2f1254a' } |
|
347 | :child => { :tag => 'a', :content => '4:def6d2f1254a' } | |
346 | } |
|
348 | } | |
347 | assert_tag :tag => 'th', |
|
349 | assert_tag :tag => 'th', | |
348 | :content => '23', |
|
350 | :content => '23', | |
349 | :attributes => { :class => 'line-num' }, |
|
351 | :attributes => { :class => 'line-num' }, | |
350 | :sibling => |
|
352 | :sibling => | |
351 | { |
|
353 | { | |
352 | :tag => 'td' , |
|
354 | :tag => 'td' , | |
353 | :content => 'jsmith' , |
|
355 | :content => 'jsmith' , | |
354 | :attributes => { :class => 'author' }, |
|
356 | :attributes => { :class => 'author' }, | |
355 | } |
|
357 | } | |
356 | assert_tag :tag => 'th', |
|
358 | assert_tag :tag => 'th', | |
357 | :content => '23', |
|
359 | :content => '23', | |
358 | :attributes => { :class => 'line-num' }, |
|
360 | :attributes => { :class => 'line-num' }, | |
359 | :sibling => { :tag => 'td', :content => /watcher =/ } |
|
361 | :sibling => { :tag => 'td', :content => /watcher =/ } | |
360 | end |
|
362 | end | |
361 |
|
363 | |||
362 | def test_annotate_not_in_tip |
|
364 | def test_annotate_not_in_tip | |
363 | @repository.fetch_changesets |
|
365 | @repository.fetch_changesets | |
364 | @repository.reload |
|
366 | @repository.reload | |
365 | assert @repository.changesets.size > 0 |
|
367 | assert @repository.changesets.size > 0 | |
366 |
|
368 | |||
367 | get :annotate, :id => PRJ_ID, |
|
369 | get :annotate, :id => PRJ_ID, | |
368 | :path => ['sources', 'welcome_controller.rb'] |
|
370 | :path => ['sources', 'welcome_controller.rb'] | |
369 | assert_response 404 |
|
371 | assert_response 404 | |
370 | assert_error_tag :content => /was not found/ |
|
372 | assert_error_tag :content => /was not found/ | |
371 | end |
|
373 | end | |
372 |
|
374 | |||
373 | def test_annotate_at_given_revision |
|
375 | def test_annotate_at_given_revision | |
374 | @repository.fetch_changesets |
|
376 | @repository.fetch_changesets | |
375 | @repository.reload |
|
377 | @repository.reload | |
376 | [2, '400bb8672109', '400', 400].each do |r1| |
|
378 | [2, '400bb8672109', '400', 400].each do |r1| | |
377 | get :annotate, :id => PRJ_ID, :rev => r1, |
|
379 | get :annotate, :id => PRJ_ID, :rev => r1, | |
378 | :path => ['sources', 'watchers_controller.rb'] |
|
380 | :path => ['sources', 'watchers_controller.rb'] | |
379 | assert_response :success |
|
381 | assert_response :success | |
380 | assert_template 'annotate' |
|
382 | assert_template 'annotate' | |
381 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ |
|
383 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ | |
382 | end |
|
384 | end | |
383 | end |
|
385 | end | |
384 |
|
386 | |||
385 | def test_annotate_latin_1_path |
|
387 | def test_annotate_latin_1_path | |
386 | [21, '21', 'adf805632193'].each do |r1| |
|
388 | [21, '21', 'adf805632193'].each do |r1| | |
387 | get :annotate, :id => PRJ_ID, |
|
389 | get :annotate, :id => PRJ_ID, | |
388 | :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 |
|
390 | :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 | |
389 | assert_response :success |
|
391 | assert_response :success | |
390 | assert_template 'annotate' |
|
392 | assert_template 'annotate' | |
391 | assert_tag :tag => 'th', |
|
393 | assert_tag :tag => 'th', | |
392 | :content => '1', |
|
394 | :content => '1', | |
393 | :attributes => { :class => 'line-num' }, |
|
395 | :attributes => { :class => 'line-num' }, | |
394 | :sibling => |
|
396 | :sibling => | |
395 | { |
|
397 | { | |
396 | :tag => 'td', |
|
398 | :tag => 'td', | |
397 | :attributes => { :class => 'revision' }, |
|
399 | :attributes => { :class => 'revision' }, | |
398 | :child => { :tag => 'a', :content => '20:709858aafd1b' } |
|
400 | :child => { :tag => 'a', :content => '20:709858aafd1b' } | |
399 | } |
|
401 | } | |
400 | assert_tag :tag => 'th', |
|
402 | assert_tag :tag => 'th', | |
401 | :content => '1', |
|
403 | :content => '1', | |
402 | :attributes => { :class => 'line-num' }, |
|
404 | :attributes => { :class => 'line-num' }, | |
403 | :sibling => |
|
405 | :sibling => | |
404 | { |
|
406 | { | |
405 | :tag => 'td' , |
|
407 | :tag => 'td' , | |
406 | :content => 'jsmith' , |
|
408 | :content => 'jsmith' , | |
407 | :attributes => { :class => 'author' }, |
|
409 | :attributes => { :class => 'author' }, | |
408 | } |
|
410 | } | |
409 | assert_tag :tag => 'th', |
|
411 | assert_tag :tag => 'th', | |
410 | :content => '1', |
|
412 | :content => '1', | |
411 | :attributes => { :class => 'line-num' }, |
|
413 | :attributes => { :class => 'line-num' }, | |
412 | :sibling => { :tag => 'td', |
|
414 | :sibling => { :tag => 'td', | |
413 | :content => /Mercurial is a distributed version control system/ } |
|
415 | :content => /Mercurial is a distributed version control system/ } | |
414 |
|
416 | |||
415 | end |
|
417 | end | |
416 | end |
|
418 | end | |
417 |
|
419 | |||
418 | def test_annotate_latin_1_contents |
|
420 | def test_annotate_latin_1_contents | |
419 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
421 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
420 | [27, '7bbf4c738e71'].each do |r1| |
|
422 | [27, '7bbf4c738e71'].each do |r1| | |
421 | get :annotate, :id => PRJ_ID, |
|
423 | get :annotate, :id => PRJ_ID, | |
422 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 |
|
424 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 | |
423 | assert_tag :tag => 'th', |
|
425 | assert_tag :tag => 'th', | |
424 | :content => '1', |
|
426 | :content => '1', | |
425 | :attributes => { :class => 'line-num' }, |
|
427 | :attributes => { :class => 'line-num' }, | |
426 | :sibling => { :tag => 'td', |
|
428 | :sibling => { :tag => 'td', | |
427 | :content => /test-#{@char_1}.txt/ } |
|
429 | :content => /test-#{@char_1}.txt/ } | |
428 | end |
|
430 | end | |
429 | end |
|
431 | end | |
430 | end |
|
432 | end | |
431 |
|
433 | |||
432 | def test_empty_revision |
|
434 | def test_empty_revision | |
433 | @repository.fetch_changesets |
|
435 | @repository.fetch_changesets | |
434 | @repository.reload |
|
436 | @repository.reload | |
435 | ['', ' ', nil].each do |r| |
|
437 | ['', ' ', nil].each do |r| | |
436 | get :revision, :id => PRJ_ID, :rev => r |
|
438 | get :revision, :id => PRJ_ID, :rev => r | |
437 | assert_response 404 |
|
439 | assert_response 404 | |
438 | assert_error_tag :content => /was not found/ |
|
440 | assert_error_tag :content => /was not found/ | |
439 | end |
|
441 | end | |
440 | end |
|
442 | end | |
441 |
|
443 | |||
442 | def test_destroy_valid_repository |
|
444 | def test_destroy_valid_repository | |
443 | @request.session[:user_id] = 1 # admin |
|
445 | @request.session[:user_id] = 1 # admin | |
444 | @repository.fetch_changesets |
|
446 | @repository.fetch_changesets | |
445 | @repository.reload |
|
447 | @repository.reload | |
446 | assert @repository.changesets.count > 0 |
|
448 | assert @repository.changesets.count > 0 | |
447 |
|
449 | |||
448 | get :destroy, :id => PRJ_ID |
|
450 | get :destroy, :id => PRJ_ID | |
449 | assert_response 302 |
|
451 | assert_response 302 | |
450 | @project.reload |
|
452 | @project.reload | |
451 | assert_nil @project.repository |
|
453 | assert_nil @project.repository | |
452 | end |
|
454 | end | |
453 |
|
455 | |||
454 | def test_destroy_invalid_repository |
|
456 | def test_destroy_invalid_repository | |
455 | @request.session[:user_id] = 1 # admin |
|
457 | @request.session[:user_id] = 1 # admin | |
456 | @repository.fetch_changesets |
|
458 | @repository.fetch_changesets | |
457 | @repository.reload |
|
459 | @repository.reload | |
458 | assert @repository.changesets.count > 0 |
|
460 | assert @repository.changesets.count > 0 | |
459 |
|
461 | |||
460 | get :destroy, :id => PRJ_ID |
|
462 | get :destroy, :id => PRJ_ID | |
461 | assert_response 302 |
|
463 | assert_response 302 | |
462 | @project.reload |
|
464 | @project.reload | |
463 | assert_nil @project.repository |
|
465 | assert_nil @project.repository | |
464 |
|
466 | |||
465 | @repository = Repository::Mercurial.create( |
|
467 | @repository = Repository::Mercurial.create( | |
466 | :project => Project.find(PRJ_ID), |
|
468 | :project => Project.find(PRJ_ID), | |
467 | :url => "/invalid", |
|
469 | :url => "/invalid", | |
468 | :path_encoding => 'ISO-8859-1' |
|
470 | :path_encoding => 'ISO-8859-1' | |
469 | ) |
|
471 | ) | |
470 | assert @repository |
|
472 | assert @repository | |
471 | @repository.fetch_changesets |
|
473 | @repository.fetch_changesets | |
472 | @repository.reload |
|
474 | @repository.reload | |
473 | assert_equal 0, @repository.changesets.count |
|
475 | assert_equal 0, @repository.changesets.count | |
474 |
|
476 | |||
475 | get :destroy, :id => PRJ_ID |
|
477 | get :destroy, :id => PRJ_ID | |
476 | assert_response 302 |
|
478 | assert_response 302 | |
477 | @project.reload |
|
479 | @project.reload | |
478 | assert_nil @project.repository |
|
480 | assert_nil @project.repository | |
479 | end |
|
481 | end | |
480 | else |
|
482 | else | |
481 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" |
|
483 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" | |
482 | def test_fake; assert true end |
|
484 | def test_fake; assert true end | |
483 | end |
|
485 | end | |
484 | end |
|
486 | end |
General Comments 0
You need to be logged in to leave comments.
Login now