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