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