1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -1,316 +1,316 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2008 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, :repositories, :enabled_modules |
|
25 | fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules | |
26 |
|
26 | |||
27 | # No '..' in the repository path |
|
27 | # No '..' in the repository path | |
28 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' |
|
28 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' | |
29 | CHAR_1_HEX = "\xc3\x9c" |
|
29 | CHAR_1_HEX = "\xc3\x9c" | |
30 |
|
30 | |||
31 | ruby19_non_utf8_pass = (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') |
|
31 | ruby19_non_utf8_pass = (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') | |
32 |
|
32 | |||
33 | def setup |
|
33 | def setup | |
34 | @controller = RepositoriesController.new |
|
34 | @controller = RepositoriesController.new | |
35 | @request = ActionController::TestRequest.new |
|
35 | @request = ActionController::TestRequest.new | |
36 | @response = ActionController::TestResponse.new |
|
36 | @response = ActionController::TestResponse.new | |
37 | User.current = nil |
|
37 | User.current = nil | |
38 | @repository = Repository::Mercurial.create( |
|
38 | @repository = Repository::Mercurial.create( | |
39 | :project => Project.find(3), |
|
39 | :project => Project.find(3), | |
40 | :url => REPOSITORY_PATH, |
|
40 | :url => REPOSITORY_PATH, | |
41 | :path_encoding => 'ISO-8859-1' |
|
41 | :path_encoding => 'ISO-8859-1' | |
42 | ) |
|
42 | ) | |
43 | assert @repository |
|
43 | assert @repository | |
44 | @diff_c_support = true |
|
44 | @diff_c_support = true | |
45 | @char_1 = CHAR_1_HEX.dup |
|
45 | @char_1 = CHAR_1_HEX.dup | |
46 | if @char_1.respond_to?(:force_encoding) |
|
46 | if @char_1.respond_to?(:force_encoding) | |
47 | @char_1.force_encoding('UTF-8') |
|
47 | @char_1.force_encoding('UTF-8') | |
48 | end |
|
48 | end | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 | if ruby19_non_utf8_pass |
|
51 | if ruby19_non_utf8_pass | |
52 | puts "TODO: Mercurial functional test fails in Ruby 1.9 " + |
|
52 | puts "TODO: Mercurial functional test fails in Ruby 1.9 " + | |
53 | "and Encoding.default_external is not UTF-8. " + |
|
53 | "and Encoding.default_external is not UTF-8. " + | |
54 | "Current value is '#{Encoding.default_external.to_s}'" |
|
54 | "Current value is '#{Encoding.default_external.to_s}'" | |
55 | def test_fake; assert true end |
|
55 | def test_fake; assert true end | |
56 | elsif File.directory?(REPOSITORY_PATH) |
|
56 | elsif File.directory?(REPOSITORY_PATH) | |
57 | def test_show |
|
57 | def test_show | |
58 | get :show, :id => 3 |
|
58 | get :show, :id => 3 | |
59 | assert_response :success |
|
59 | assert_response :success | |
60 | assert_template 'show' |
|
60 | assert_template 'show' | |
61 | assert_not_nil assigns(:entries) |
|
61 | assert_not_nil assigns(:entries) | |
62 | assert_not_nil assigns(:changesets) |
|
62 | assert_not_nil assigns(:changesets) | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | def test_show_root |
|
65 | def test_show_root | |
66 | get :show, :id => 3 |
|
66 | get :show, :id => 3 | |
67 | assert_response :success |
|
67 | assert_response :success | |
68 | assert_template 'show' |
|
68 | assert_template 'show' | |
69 | assert_not_nil assigns(:entries) |
|
69 | assert_not_nil assigns(:entries) | |
70 | assert_equal 4, assigns(:entries).size |
|
70 | assert_equal 4, assigns(:entries).size | |
71 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
71 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} | |
72 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
72 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} | |
73 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
73 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def test_show_directory |
|
76 | def test_show_directory | |
77 | get :show, :id => 3, :path => ['images'] |
|
77 | get :show, :id => 3, :path => ['images'] | |
78 | assert_response :success |
|
78 | assert_response :success | |
79 | assert_template 'show' |
|
79 | assert_template 'show' | |
80 | assert_not_nil assigns(:entries) |
|
80 | assert_not_nil assigns(:entries) | |
81 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
81 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
82 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
82 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
83 | assert_not_nil entry |
|
83 | assert_not_nil entry | |
84 | assert_equal 'file', entry.kind |
|
84 | assert_equal 'file', entry.kind | |
85 | assert_equal 'images/edit.png', entry.path |
|
85 | assert_equal 'images/edit.png', entry.path | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | def test_show_at_given_revision |
|
88 | def test_show_at_given_revision | |
89 | [0, '0', '0885933ad4f6'].each do |r1| |
|
89 | [0, '0', '0885933ad4f6'].each do |r1| | |
90 | get :show, :id => 3, :path => ['images'], :rev => r1 |
|
90 | get :show, :id => 3, :path => ['images'], :rev => r1 | |
91 | assert_response :success |
|
91 | assert_response :success | |
92 | assert_template 'show' |
|
92 | assert_template 'show' | |
93 | assert_not_nil assigns(:entries) |
|
93 | assert_not_nil assigns(:entries) | |
94 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
94 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |
95 | end |
|
95 | end | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | def test_show_directory_sql_escape_percent |
|
98 | def test_show_directory_sql_escape_percent | |
99 | [13, '13', '3a330eb32958'].each do |r1| |
|
99 | [13, '13', '3a330eb32958'].each do |r1| | |
100 | get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1 |
|
100 | get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1 | |
101 | assert_response :success |
|
101 | assert_response :success | |
102 | assert_template 'show' |
|
102 | assert_template 'show' | |
103 |
|
103 | |||
104 | assert_not_nil assigns(:entries) |
|
104 | assert_not_nil assigns(:entries) | |
105 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name) |
|
105 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name) | |
106 | changesets = assigns(:changesets) |
|
106 | changesets = assigns(:changesets) | |
107 |
|
107 | |||
108 | ## This is not yet implemented. |
|
108 | ## This is not yet implemented. | |
109 | # assert_not_nil changesets |
|
109 | # assert_not_nil changesets | |
110 | # assert_equal %w(13 11 10 9), changesets.collect(&:revision) |
|
110 | # assert_equal %w(13 11 10 9), changesets.collect(&:revision) | |
111 | end |
|
111 | end | |
112 | end |
|
112 | end | |
113 |
|
113 | |||
114 | def test_show_directory_latin_1 |
|
114 | def test_show_directory_latin_1 | |
115 | @repository.fetch_changesets |
|
115 | @repository.fetch_changesets | |
116 | @repository.reload |
|
116 | @repository.reload | |
117 | [21, '21', 'adf805632193'].each do |r1| |
|
117 | [21, '21', 'adf805632193'].each do |r1| | |
118 | get :show, :id => 3, :path => ['latin-1-dir'], :rev => r1 |
|
118 | get :show, :id => 3, :path => ['latin-1-dir'], :rev => r1 | |
119 | assert_response :success |
|
119 | assert_response :success | |
120 | assert_template 'show' |
|
120 | assert_template 'show' | |
121 |
|
121 | |||
122 | assert_not_nil assigns(:entries) |
|
122 | assert_not_nil assigns(:entries) | |
123 | assert_equal ["make-latin-1-file.rb", |
|
123 | assert_equal ["make-latin-1-file.rb", | |
124 | "test-#{@char_1}-1.txt", |
|
124 | "test-#{@char_1}-1.txt", | |
125 | "test-#{@char_1}-2.txt", |
|
125 | "test-#{@char_1}-2.txt", | |
126 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) |
|
126 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) | |
127 | changesets = assigns(:changesets) |
|
127 | changesets = assigns(:changesets) | |
128 | assert_not_nil changesets |
|
128 | assert_not_nil changesets | |
129 | assert_equal %w(21 20 19 18 17), changesets.collect(&:revision) |
|
129 | assert_equal %w(27 21 20 19 18 17), changesets.collect(&:revision) | |
130 | end |
|
130 | end | |
131 | end |
|
131 | end | |
132 |
|
132 | |||
133 | def test_changes |
|
133 | def test_changes | |
134 | get :changes, :id => 3, :path => ['images', 'edit.png'] |
|
134 | get :changes, :id => 3, :path => ['images', 'edit.png'] | |
135 | assert_response :success |
|
135 | assert_response :success | |
136 | assert_template 'changes' |
|
136 | assert_template 'changes' | |
137 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
137 | assert_tag :tag => 'h2', :content => 'edit.png' | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | def test_entry_show |
|
140 | def test_entry_show | |
141 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] |
|
141 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] | |
142 | assert_response :success |
|
142 | assert_response :success | |
143 | assert_template 'entry' |
|
143 | assert_template 'entry' | |
144 | # Line 10 |
|
144 | # Line 10 | |
145 | assert_tag :tag => 'th', |
|
145 | assert_tag :tag => 'th', | |
146 | :content => '10', |
|
146 | :content => '10', | |
147 | :attributes => { :class => 'line-num' }, |
|
147 | :attributes => { :class => 'line-num' }, | |
148 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
|
148 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } | |
149 | end |
|
149 | end | |
150 |
|
150 | |||
151 | def test_entry_show_latin_1 |
|
151 | def test_entry_show_latin_1 | |
152 | [21, '21', 'adf805632193'].each do |r1| |
|
152 | [21, '21', 'adf805632193'].each do |r1| | |
153 | get :entry, :id => 3, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 |
|
153 | get :entry, :id => 3, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 | |
154 | assert_response :success |
|
154 | assert_response :success | |
155 | assert_template 'entry' |
|
155 | assert_template 'entry' | |
156 | assert_tag :tag => 'th', |
|
156 | assert_tag :tag => 'th', | |
157 | :content => '1', |
|
157 | :content => '1', | |
158 | :attributes => { :class => 'line-num' }, |
|
158 | :attributes => { :class => 'line-num' }, | |
159 | :sibling => { :tag => 'td', :content => /Mercurial is a distributed version control system/ } |
|
159 | :sibling => { :tag => 'td', :content => /Mercurial is a distributed version control system/ } | |
160 | end |
|
160 | end | |
161 | end |
|
161 | end | |
162 |
|
162 | |||
163 | def test_entry_download |
|
163 | def test_entry_download | |
164 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' |
|
164 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' | |
165 | assert_response :success |
|
165 | assert_response :success | |
166 | # File content |
|
166 | # File content | |
167 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
|
167 | assert @response.body.include?('WITHOUT ANY WARRANTY') | |
168 | end |
|
168 | end | |
169 |
|
169 | |||
170 | def test_directory_entry |
|
170 | def test_directory_entry | |
171 | get :entry, :id => 3, :path => ['sources'] |
|
171 | get :entry, :id => 3, :path => ['sources'] | |
172 | assert_response :success |
|
172 | assert_response :success | |
173 | assert_template 'show' |
|
173 | assert_template 'show' | |
174 | assert_not_nil assigns(:entry) |
|
174 | assert_not_nil assigns(:entry) | |
175 | assert_equal 'sources', assigns(:entry).name |
|
175 | assert_equal 'sources', assigns(:entry).name | |
176 | end |
|
176 | end | |
177 |
|
177 | |||
178 | def test_diff |
|
178 | def test_diff | |
179 | @repository.fetch_changesets |
|
179 | @repository.fetch_changesets | |
180 | @repository.reload |
|
180 | @repository.reload | |
181 |
|
181 | |||
182 | [4, '4', 'def6d2f1254a'].each do |r1| |
|
182 | [4, '4', 'def6d2f1254a'].each do |r1| | |
183 | # Full diff of changeset 4 |
|
183 | # Full diff of changeset 4 | |
184 | get :diff, :id => 3, :rev => r1 |
|
184 | get :diff, :id => 3, :rev => r1 | |
185 | assert_response :success |
|
185 | assert_response :success | |
186 | assert_template 'diff' |
|
186 | assert_template 'diff' | |
187 |
|
187 | |||
188 | if @diff_c_support |
|
188 | if @diff_c_support | |
189 | # Line 22 removed |
|
189 | # Line 22 removed | |
190 | assert_tag :tag => 'th', |
|
190 | assert_tag :tag => 'th', | |
191 | :content => '22', |
|
191 | :content => '22', | |
192 | :sibling => { :tag => 'td', |
|
192 | :sibling => { :tag => 'td', | |
193 | :attributes => { :class => /diff_out/ }, |
|
193 | :attributes => { :class => /diff_out/ }, | |
194 | :content => /def remove/ } |
|
194 | :content => /def remove/ } | |
195 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ |
|
195 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ | |
196 | end |
|
196 | end | |
197 | end |
|
197 | end | |
198 | end |
|
198 | end | |
199 |
|
199 | |||
200 | def test_diff_two_revs |
|
200 | def test_diff_two_revs | |
201 | @repository.fetch_changesets |
|
201 | @repository.fetch_changesets | |
202 | @repository.reload |
|
202 | @repository.reload | |
203 |
|
203 | |||
204 | [2, '400bb8672109', '400', 400].each do |r1| |
|
204 | [2, '400bb8672109', '400', 400].each do |r1| | |
205 | [4, 'def6d2f1254a'].each do |r2| |
|
205 | [4, 'def6d2f1254a'].each do |r2| | |
206 | get :diff, :id => 3, :rev => r1, |
|
206 | get :diff, :id => 3, :rev => r1, | |
207 | :rev_to => r2 |
|
207 | :rev_to => r2 | |
208 | assert_response :success |
|
208 | assert_response :success | |
209 | assert_template 'diff' |
|
209 | assert_template 'diff' | |
210 |
|
210 | |||
211 | diff = assigns(:diff) |
|
211 | diff = assigns(:diff) | |
212 | assert_not_nil diff |
|
212 | assert_not_nil diff | |
213 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/ |
|
213 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/ | |
214 | end |
|
214 | end | |
215 | end |
|
215 | end | |
216 | end |
|
216 | end | |
217 |
|
217 | |||
218 | def test_diff_latin_1 |
|
218 | def test_diff_latin_1 | |
219 | [21, 'adf805632193'].each do |r1| |
|
219 | [21, 'adf805632193'].each do |r1| | |
220 | get :diff, :id => 3, :rev => r1 |
|
220 | get :diff, :id => 3, :rev => r1 | |
221 | assert_response :success |
|
221 | assert_response :success | |
222 | assert_template 'diff' |
|
222 | assert_template 'diff' | |
223 | assert_tag :tag => 'th', |
|
223 | assert_tag :tag => 'th', | |
224 | :content => '2', |
|
224 | :content => '2', | |
225 | :sibling => { :tag => 'td', |
|
225 | :sibling => { :tag => 'td', | |
226 | :attributes => { :class => /diff_in/ }, |
|
226 | :attributes => { :class => /diff_in/ }, | |
227 | :content => /It is written in Python/ } |
|
227 | :content => /It is written in Python/ } | |
228 | end |
|
228 | end | |
229 | end |
|
229 | end | |
230 |
|
230 | |||
231 | def test_annotate |
|
231 | def test_annotate | |
232 | get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] |
|
232 | get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] | |
233 | assert_response :success |
|
233 | assert_response :success | |
234 | assert_template 'annotate' |
|
234 | assert_template 'annotate' | |
235 | # Line 23, revision 4:def6d2f1254a |
|
235 | # Line 23, revision 4:def6d2f1254a | |
236 | assert_tag :tag => 'th', |
|
236 | assert_tag :tag => 'th', | |
237 | :content => '23', |
|
237 | :content => '23', | |
238 | :attributes => { :class => 'line-num' }, |
|
238 | :attributes => { :class => 'line-num' }, | |
239 | :sibling => |
|
239 | :sibling => | |
240 | { |
|
240 | { | |
241 | :tag => 'td', |
|
241 | :tag => 'td', | |
242 | :attributes => { :class => 'revision' }, |
|
242 | :attributes => { :class => 'revision' }, | |
243 | :child => { :tag => 'a', :content => '4:def6d2f1254a' } |
|
243 | :child => { :tag => 'a', :content => '4:def6d2f1254a' } | |
244 | } |
|
244 | } | |
245 | assert_tag :tag => 'th', |
|
245 | assert_tag :tag => 'th', | |
246 | :content => '23', |
|
246 | :content => '23', | |
247 | :attributes => { :class => 'line-num' }, |
|
247 | :attributes => { :class => 'line-num' }, | |
248 | :sibling => |
|
248 | :sibling => | |
249 | { |
|
249 | { | |
250 | :tag => 'td' , |
|
250 | :tag => 'td' , | |
251 | :content => 'jsmith' , |
|
251 | :content => 'jsmith' , | |
252 | :attributes => { :class => 'author' }, |
|
252 | :attributes => { :class => 'author' }, | |
253 | } |
|
253 | } | |
254 | assert_tag :tag => 'th', |
|
254 | assert_tag :tag => 'th', | |
255 | :content => '23', |
|
255 | :content => '23', | |
256 | :attributes => { :class => 'line-num' }, |
|
256 | :attributes => { :class => 'line-num' }, | |
257 | :sibling => { :tag => 'td', :content => /watcher =/ } |
|
257 | :sibling => { :tag => 'td', :content => /watcher =/ } | |
258 | end |
|
258 | end | |
259 |
|
259 | |||
260 | def test_annotate_at_given_revision |
|
260 | def test_annotate_at_given_revision | |
261 | @repository.fetch_changesets |
|
261 | @repository.fetch_changesets | |
262 | @repository.reload |
|
262 | @repository.reload | |
263 | [2, '400bb8672109', '400', 400].each do |r1| |
|
263 | [2, '400bb8672109', '400', 400].each do |r1| | |
264 | get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb'] |
|
264 | get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb'] | |
265 | assert_response :success |
|
265 | assert_response :success | |
266 | assert_template 'annotate' |
|
266 | assert_template 'annotate' | |
267 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ |
|
267 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ | |
268 | end |
|
268 | end | |
269 | end |
|
269 | end | |
270 |
|
270 | |||
271 | def test_annotate_latin_1 |
|
271 | def test_annotate_latin_1 | |
272 | [21, '21', 'adf805632193'].each do |r1| |
|
272 | [21, '21', 'adf805632193'].each do |r1| | |
273 | get :annotate, :id => 3, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 |
|
273 | get :annotate, :id => 3, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 | |
274 | assert_response :success |
|
274 | assert_response :success | |
275 | assert_template 'annotate' |
|
275 | assert_template 'annotate' | |
276 | assert_tag :tag => 'th', |
|
276 | assert_tag :tag => 'th', | |
277 | :content => '1', |
|
277 | :content => '1', | |
278 | :attributes => { :class => 'line-num' }, |
|
278 | :attributes => { :class => 'line-num' }, | |
279 | :sibling => |
|
279 | :sibling => | |
280 | { |
|
280 | { | |
281 | :tag => 'td', |
|
281 | :tag => 'td', | |
282 | :attributes => { :class => 'revision' }, |
|
282 | :attributes => { :class => 'revision' }, | |
283 | :child => { :tag => 'a', :content => '20:709858aafd1b' } |
|
283 | :child => { :tag => 'a', :content => '20:709858aafd1b' } | |
284 | } |
|
284 | } | |
285 | assert_tag :tag => 'th', |
|
285 | assert_tag :tag => 'th', | |
286 | :content => '1', |
|
286 | :content => '1', | |
287 | :attributes => { :class => 'line-num' }, |
|
287 | :attributes => { :class => 'line-num' }, | |
288 | :sibling => |
|
288 | :sibling => | |
289 | { |
|
289 | { | |
290 | :tag => 'td' , |
|
290 | :tag => 'td' , | |
291 | :content => 'jsmith' , |
|
291 | :content => 'jsmith' , | |
292 | :attributes => { :class => 'author' }, |
|
292 | :attributes => { :class => 'author' }, | |
293 |
|
293 | |||
294 | } |
|
294 | } | |
295 | assert_tag :tag => 'th', |
|
295 | assert_tag :tag => 'th', | |
296 | :content => '1', |
|
296 | :content => '1', | |
297 | :attributes => { :class => 'line-num' }, |
|
297 | :attributes => { :class => 'line-num' }, | |
298 | :sibling => { :tag => 'td', :content => /Mercurial is a distributed version control system/ } |
|
298 | :sibling => { :tag => 'td', :content => /Mercurial is a distributed version control system/ } | |
299 |
|
299 | |||
300 | end |
|
300 | end | |
301 | end |
|
301 | end | |
302 |
|
302 | |||
303 | def test_empty_revision |
|
303 | def test_empty_revision | |
304 | @repository.fetch_changesets |
|
304 | @repository.fetch_changesets | |
305 | @repository.reload |
|
305 | @repository.reload | |
306 | ['', ' ', nil].each do |r| |
|
306 | ['', ' ', nil].each do |r| | |
307 | get :revision, :id => 3, :rev => r |
|
307 | get :revision, :id => 3, :rev => r | |
308 | assert_response 404 |
|
308 | assert_response 404 | |
309 | assert_error_tag :content => /was not found/ |
|
309 | assert_error_tag :content => /was not found/ | |
310 | end |
|
310 | end | |
311 | end |
|
311 | end | |
312 | else |
|
312 | else | |
313 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" |
|
313 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" | |
314 | def test_fake; assert true end |
|
314 | def test_fake; assert true end | |
315 | end |
|
315 | end | |
316 | end |
|
316 | end |
@@ -1,299 +1,303 | |||||
1 | require File.expand_path('../../../../../../test_helper', __FILE__) |
|
1 | require File.expand_path('../../../../../../test_helper', __FILE__) | |
2 | begin |
|
2 | begin | |
3 | require 'mocha' |
|
3 | require 'mocha' | |
4 |
|
4 | |||
5 | class MercurialAdapterTest < ActiveSupport::TestCase |
|
5 | class MercurialAdapterTest < ActiveSupport::TestCase | |
6 |
|
6 | |||
7 | HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR |
|
7 | HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR | |
8 | TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME |
|
8 | TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME | |
9 | TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION |
|
9 | TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION | |
10 |
|
10 | |||
11 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' |
|
11 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' | |
12 |
|
12 | |||
13 | CHAR_1_HEX = "\xc3\x9c" |
|
13 | CHAR_1_HEX = "\xc3\x9c" | |
14 |
|
14 | |||
15 | if File.directory?(REPOSITORY_PATH) |
|
15 | if File.directory?(REPOSITORY_PATH) | |
16 | def setup |
|
16 | def setup | |
17 | @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH) |
|
17 | @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH) | |
18 | @diff_c_support = true |
|
18 | @diff_c_support = true | |
19 |
|
19 | |||
20 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" |
|
20 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" | |
21 |
@branch_char_ |
|
21 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" | |
|
22 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" | |||
22 | if @tag_char_1.respond_to?(:force_encoding) |
|
23 | if @tag_char_1.respond_to?(:force_encoding) | |
23 | @tag_char_1.force_encoding('UTF-8') |
|
24 | @tag_char_1.force_encoding('UTF-8') | |
|
25 | @branch_char_0.force_encoding('UTF-8') | |||
24 | @branch_char_1.force_encoding('UTF-8') |
|
26 | @branch_char_1.force_encoding('UTF-8') | |
25 | end |
|
27 | end | |
26 | end |
|
28 | end | |
27 |
|
29 | |||
28 | def test_hgversion |
|
30 | def test_hgversion | |
29 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], |
|
31 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], | |
30 | "Mercurial Distributed SCM (1.0)\n" => [1,0], |
|
32 | "Mercurial Distributed SCM (1.0)\n" => [1,0], | |
31 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, |
|
33 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, | |
32 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], |
|
34 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], | |
33 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, |
|
35 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, | |
34 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], |
|
36 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], | |
35 | "(1.6)\n(1.7)\n(1.8)" => [1,6], |
|
37 | "(1.6)\n(1.7)\n(1.8)" => [1,6], | |
36 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} |
|
38 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} | |
37 |
|
39 | |||
38 | to_test.each do |s, v| |
|
40 | to_test.each do |s, v| | |
39 | test_hgversion_for(s, v) |
|
41 | test_hgversion_for(s, v) | |
40 | end |
|
42 | end | |
41 | end |
|
43 | end | |
42 |
|
44 | |||
43 | def test_template_path |
|
45 | def test_template_path | |
44 | to_test = { [0,9,5] => "0.9.5", |
|
46 | to_test = { [0,9,5] => "0.9.5", | |
45 | [1,0] => "1.0", |
|
47 | [1,0] => "1.0", | |
46 | [] => "1.0", |
|
48 | [] => "1.0", | |
47 | [1,0,1] => "1.0", |
|
49 | [1,0,1] => "1.0", | |
48 | [1,7] => "1.0", |
|
50 | [1,7] => "1.0", | |
49 | [1,7,1] => "1.0" } |
|
51 | [1,7,1] => "1.0" } | |
50 | to_test.each do |v, template| |
|
52 | to_test.each do |v, template| | |
51 | test_template_path_for(v, template) |
|
53 | test_template_path_for(v, template) | |
52 | end |
|
54 | end | |
53 | end |
|
55 | end | |
54 |
|
56 | |||
55 | def test_info |
|
57 | def test_info | |
56 | [REPOSITORY_PATH, REPOSITORY_PATH + "/", |
|
58 | [REPOSITORY_PATH, REPOSITORY_PATH + "/", | |
57 | REPOSITORY_PATH + "//"].each do |repo| |
|
59 | REPOSITORY_PATH + "//"].each do |repo| | |
58 | adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) |
|
60 | adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) | |
59 | repo_path = adp.info.root_url.gsub(/\\/, "/") |
|
61 | repo_path = adp.info.root_url.gsub(/\\/, "/") | |
60 | assert_equal REPOSITORY_PATH, repo_path |
|
62 | assert_equal REPOSITORY_PATH, repo_path | |
61 |
assert_equal '2 |
|
63 | assert_equal '28', adp.info.lastrev.revision | |
62 | assert_equal '3ae45e2d177d',adp.info.lastrev.scmid |
|
64 | assert_equal '3ae45e2d177d',adp.info.lastrev.scmid | |
63 | end |
|
65 | end | |
64 | end |
|
66 | end | |
65 |
|
67 | |||
66 | def test_revisions |
|
68 | def test_revisions | |
67 | revisions = @adapter.revisions(nil, 2, 4) |
|
69 | revisions = @adapter.revisions(nil, 2, 4) | |
68 | assert_equal 3, revisions.size |
|
70 | assert_equal 3, revisions.size | |
69 | assert_equal '2', revisions[0].revision |
|
71 | assert_equal '2', revisions[0].revision | |
70 | assert_equal '400bb8672109', revisions[0].scmid |
|
72 | assert_equal '400bb8672109', revisions[0].scmid | |
71 | assert_equal '4', revisions[2].revision |
|
73 | assert_equal '4', revisions[2].revision | |
72 | assert_equal 'def6d2f1254a', revisions[2].scmid |
|
74 | assert_equal 'def6d2f1254a', revisions[2].scmid | |
73 |
|
75 | |||
74 | revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) |
|
76 | revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) | |
75 | assert_equal 2, revisions.size |
|
77 | assert_equal 2, revisions.size | |
76 | assert_equal '2', revisions[0].revision |
|
78 | assert_equal '2', revisions[0].revision | |
77 | assert_equal '400bb8672109', revisions[0].scmid |
|
79 | assert_equal '400bb8672109', revisions[0].scmid | |
78 | end |
|
80 | end | |
79 |
|
81 | |||
80 | def test_diff |
|
82 | def test_diff | |
81 | if @adapter.class.client_version_above?([1, 2]) |
|
83 | if @adapter.class.client_version_above?([1, 2]) | |
82 | assert_nil @adapter.diff(nil, '100000') |
|
84 | assert_nil @adapter.diff(nil, '100000') | |
83 | end |
|
85 | end | |
84 | assert_nil @adapter.diff(nil, '100000', '200000') |
|
86 | assert_nil @adapter.diff(nil, '100000', '200000') | |
85 | [2, '400bb8672109', '400', 400].each do |r1| |
|
87 | [2, '400bb8672109', '400', 400].each do |r1| | |
86 | diff1 = @adapter.diff(nil, r1) |
|
88 | diff1 = @adapter.diff(nil, r1) | |
87 | if @diff_c_support |
|
89 | if @diff_c_support | |
88 | assert_equal 28, diff1.size |
|
90 | assert_equal 28, diff1.size | |
89 | buf = diff1[24].gsub(/\r\n|\r|\n/, "") |
|
91 | buf = diff1[24].gsub(/\r\n|\r|\n/, "") | |
90 | assert_equal "+ return true unless klass.respond_to?('watched_by')", buf |
|
92 | assert_equal "+ return true unless klass.respond_to?('watched_by')", buf | |
91 | else |
|
93 | else | |
92 | assert_equal 0, diff1.size |
|
94 | assert_equal 0, diff1.size | |
93 | end |
|
95 | end | |
94 | [4, 'def6d2f1254a'].each do |r2| |
|
96 | [4, 'def6d2f1254a'].each do |r2| | |
95 | diff2 = @adapter.diff(nil,r1,r2) |
|
97 | diff2 = @adapter.diff(nil,r1,r2) | |
96 | assert_equal 49, diff2.size |
|
98 | assert_equal 49, diff2.size | |
97 | buf = diff2[41].gsub(/\r\n|\r|\n/, "") |
|
99 | buf = diff2[41].gsub(/\r\n|\r|\n/, "") | |
98 | assert_equal "+class WelcomeController < ApplicationController", buf |
|
100 | assert_equal "+class WelcomeController < ApplicationController", buf | |
99 | diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) |
|
101 | diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) | |
100 | assert_equal 20, diff3.size |
|
102 | assert_equal 20, diff3.size | |
101 | buf = diff3[12].gsub(/\r\n|\r|\n/, "") |
|
103 | buf = diff3[12].gsub(/\r\n|\r|\n/, "") | |
102 | assert_equal "+ @watched.remove_watcher(user)", buf |
|
104 | assert_equal "+ @watched.remove_watcher(user)", buf | |
103 | end |
|
105 | end | |
104 | end |
|
106 | end | |
105 | end |
|
107 | end | |
106 |
|
108 | |||
107 | def test_diff_made_by_revision |
|
109 | def test_diff_made_by_revision | |
108 | if @diff_c_support |
|
110 | if @diff_c_support | |
109 | [24, '24', '4cddb4e45f52'].each do |r1| |
|
111 | [24, '24', '4cddb4e45f52'].each do |r1| | |
110 | diff1 = @adapter.diff(nil, r1) |
|
112 | diff1 = @adapter.diff(nil, r1) | |
111 | assert_equal 5, diff1.size |
|
113 | assert_equal 5, diff1.size | |
112 | buf = diff1[4].gsub(/\r\n|\r|\n/, "") |
|
114 | buf = diff1[4].gsub(/\r\n|\r|\n/, "") | |
113 | assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf |
|
115 | assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf | |
114 | end |
|
116 | end | |
115 | end |
|
117 | end | |
116 | end |
|
118 | end | |
117 |
|
119 | |||
118 | def test_cat |
|
120 | def test_cat | |
119 | [2, '400bb8672109', '400', 400].each do |r| |
|
121 | [2, '400bb8672109', '400', 400].each do |r| | |
120 | buf = @adapter.cat('sources/welcome_controller.rb', r) |
|
122 | buf = @adapter.cat('sources/welcome_controller.rb', r) | |
121 | assert buf |
|
123 | assert buf | |
122 | lines = buf.split("\r\n") |
|
124 | lines = buf.split("\r\n") | |
123 | assert_equal 25, lines.length |
|
125 | assert_equal 25, lines.length | |
124 | assert_equal 'class WelcomeController < ApplicationController', lines[17] |
|
126 | assert_equal 'class WelcomeController < ApplicationController', lines[17] | |
125 | end |
|
127 | end | |
126 | assert_nil @adapter.cat('sources/welcome_controller.rb') |
|
128 | assert_nil @adapter.cat('sources/welcome_controller.rb') | |
127 | end |
|
129 | end | |
128 |
|
130 | |||
129 | def test_annotate |
|
131 | def test_annotate | |
130 | assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines |
|
132 | assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines | |
131 | [2, '400bb8672109', '400', 400].each do |r| |
|
133 | [2, '400bb8672109', '400', 400].each do |r| | |
132 | ann = @adapter.annotate('sources/welcome_controller.rb', r) |
|
134 | ann = @adapter.annotate('sources/welcome_controller.rb', r) | |
133 | assert ann |
|
135 | assert ann | |
134 | assert_equal '1', ann.revisions[17].revision |
|
136 | assert_equal '1', ann.revisions[17].revision | |
135 | assert_equal '9d5b5b004199', ann.revisions[17].identifier |
|
137 | assert_equal '9d5b5b004199', ann.revisions[17].identifier | |
136 | assert_equal 'jsmith', ann.revisions[0].author |
|
138 | assert_equal 'jsmith', ann.revisions[0].author | |
137 | assert_equal 25, ann.lines.length |
|
139 | assert_equal 25, ann.lines.length | |
138 | assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] |
|
140 | assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] | |
139 | end |
|
141 | end | |
140 | end |
|
142 | end | |
141 |
|
143 | |||
142 | def test_entries |
|
144 | def test_entries | |
143 | assert_nil @adapter.entries(nil, '100000') |
|
145 | assert_nil @adapter.entries(nil, '100000') | |
144 |
|
146 | |||
145 | assert_equal 1, @adapter.entries("sources", 3).size |
|
147 | assert_equal 1, @adapter.entries("sources", 3).size | |
146 | assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size |
|
148 | assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size | |
147 |
|
149 | |||
148 | [2, '400bb8672109', '400', 400].each do |r| |
|
150 | [2, '400bb8672109', '400', 400].each do |r| | |
149 | entries1 = @adapter.entries(nil, r) |
|
151 | entries1 = @adapter.entries(nil, r) | |
150 | assert entries1 |
|
152 | assert entries1 | |
151 | assert_equal 3, entries1.size |
|
153 | assert_equal 3, entries1.size | |
152 | assert_equal 'sources', entries1[1].name |
|
154 | assert_equal 'sources', entries1[1].name | |
153 | assert_equal 'sources', entries1[1].path |
|
155 | assert_equal 'sources', entries1[1].path | |
154 | assert_equal 'dir', entries1[1].kind |
|
156 | assert_equal 'dir', entries1[1].kind | |
155 | readme = entries1[2] |
|
157 | readme = entries1[2] | |
156 | assert_equal 'README', readme.name |
|
158 | assert_equal 'README', readme.name | |
157 | assert_equal 'README', readme.path |
|
159 | assert_equal 'README', readme.path | |
158 | assert_equal 'file', readme.kind |
|
160 | assert_equal 'file', readme.kind | |
159 | assert_equal 27, readme.size |
|
161 | assert_equal 27, readme.size | |
160 | assert_equal '1', readme.lastrev.revision |
|
162 | assert_equal '1', readme.lastrev.revision | |
161 | assert_equal '9d5b5b004199', readme.lastrev.identifier |
|
163 | assert_equal '9d5b5b004199', readme.lastrev.identifier | |
162 | # 2007-12-14 10:24:01 +0100 |
|
164 | # 2007-12-14 10:24:01 +0100 | |
163 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time |
|
165 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time | |
164 |
|
166 | |||
165 | entries2 = @adapter.entries('sources', r) |
|
167 | entries2 = @adapter.entries('sources', r) | |
166 | assert entries2 |
|
168 | assert entries2 | |
167 | assert_equal 2, entries2.size |
|
169 | assert_equal 2, entries2.size | |
168 | assert_equal 'watchers_controller.rb', entries2[0].name |
|
170 | assert_equal 'watchers_controller.rb', entries2[0].name | |
169 | assert_equal 'sources/watchers_controller.rb', entries2[0].path |
|
171 | assert_equal 'sources/watchers_controller.rb', entries2[0].path | |
170 | assert_equal 'file', entries2[0].kind |
|
172 | assert_equal 'file', entries2[0].kind | |
171 | assert_equal 'welcome_controller.rb', entries2[1].name |
|
173 | assert_equal 'welcome_controller.rb', entries2[1].name | |
172 | assert_equal 'sources/welcome_controller.rb', entries2[1].path |
|
174 | assert_equal 'sources/welcome_controller.rb', entries2[1].path | |
173 | assert_equal 'file', entries2[1].kind |
|
175 | assert_equal 'file', entries2[1].kind | |
174 | end |
|
176 | end | |
175 | end |
|
177 | end | |
176 |
|
178 | |||
177 | def test_entries_tag |
|
179 | def test_entries_tag | |
178 | entries1 = @adapter.entries(nil, 'tag_test.00') |
|
180 | entries1 = @adapter.entries(nil, 'tag_test.00') | |
179 | assert entries1 |
|
181 | assert entries1 | |
180 | assert_equal 3, entries1.size |
|
182 | assert_equal 3, entries1.size | |
181 | assert_equal 'sources', entries1[1].name |
|
183 | assert_equal 'sources', entries1[1].name | |
182 | assert_equal 'sources', entries1[1].path |
|
184 | assert_equal 'sources', entries1[1].path | |
183 | assert_equal 'dir', entries1[1].kind |
|
185 | assert_equal 'dir', entries1[1].kind | |
184 | readme = entries1[2] |
|
186 | readme = entries1[2] | |
185 | assert_equal 'README', readme.name |
|
187 | assert_equal 'README', readme.name | |
186 | assert_equal 'README', readme.path |
|
188 | assert_equal 'README', readme.path | |
187 | assert_equal 'file', readme.kind |
|
189 | assert_equal 'file', readme.kind | |
188 | assert_equal 21, readme.size |
|
190 | assert_equal 21, readme.size | |
189 | assert_equal '0', readme.lastrev.revision |
|
191 | assert_equal '0', readme.lastrev.revision | |
190 | assert_equal '0885933ad4f6', readme.lastrev.identifier |
|
192 | assert_equal '0885933ad4f6', readme.lastrev.identifier | |
191 | # 2007-12-14 10:22:52 +0100 |
|
193 | # 2007-12-14 10:22:52 +0100 | |
192 | assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time |
|
194 | assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time | |
193 | end |
|
195 | end | |
194 |
|
196 | |||
195 | def test_entries_branch |
|
197 | def test_entries_branch | |
196 | entries1 = @adapter.entries(nil, 'test-branch-00') |
|
198 | entries1 = @adapter.entries(nil, 'test-branch-00') | |
197 | assert entries1 |
|
199 | assert entries1 | |
198 | assert_equal 5, entries1.size |
|
200 | assert_equal 5, entries1.size | |
199 | assert_equal 'sql_escape', entries1[2].name |
|
201 | assert_equal 'sql_escape', entries1[2].name | |
200 | assert_equal 'sql_escape', entries1[2].path |
|
202 | assert_equal 'sql_escape', entries1[2].path | |
201 | assert_equal 'dir', entries1[2].kind |
|
203 | assert_equal 'dir', entries1[2].kind | |
202 | readme = entries1[4] |
|
204 | readme = entries1[4] | |
203 | assert_equal 'README', readme.name |
|
205 | assert_equal 'README', readme.name | |
204 | assert_equal 'README', readme.path |
|
206 | assert_equal 'README', readme.path | |
205 | assert_equal 'file', readme.kind |
|
207 | assert_equal 'file', readme.kind | |
206 | assert_equal 365, readme.size |
|
208 | assert_equal 365, readme.size | |
207 | assert_equal '8', readme.lastrev.revision |
|
209 | assert_equal '8', readme.lastrev.revision | |
208 | assert_equal 'c51f5bb613cd', readme.lastrev.identifier |
|
210 | assert_equal 'c51f5bb613cd', readme.lastrev.identifier | |
209 | # 2001-02-01 00:00:00 -0900 |
|
211 | # 2001-02-01 00:00:00 -0900 | |
210 | assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time |
|
212 | assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time | |
211 | end |
|
213 | end | |
212 |
|
214 | |||
213 | def test_locate_on_outdated_repository |
|
215 | def test_locate_on_outdated_repository | |
214 | assert_equal 1, @adapter.entries("images", 0).size |
|
216 | assert_equal 1, @adapter.entries("images", 0).size | |
215 | assert_equal 2, @adapter.entries("images").size |
|
217 | assert_equal 2, @adapter.entries("images").size | |
216 | assert_equal 2, @adapter.entries("images", 2).size |
|
218 | assert_equal 2, @adapter.entries("images", 2).size | |
217 | end |
|
219 | end | |
218 |
|
220 | |||
219 | def test_access_by_nodeid |
|
221 | def test_access_by_nodeid | |
220 | path = 'sources/welcome_controller.rb' |
|
222 | path = 'sources/welcome_controller.rb' | |
221 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') |
|
223 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') | |
222 | end |
|
224 | end | |
223 |
|
225 | |||
224 | def test_access_by_fuzzy_nodeid |
|
226 | def test_access_by_fuzzy_nodeid | |
225 | path = 'sources/welcome_controller.rb' |
|
227 | path = 'sources/welcome_controller.rb' | |
226 | # falls back to nodeid |
|
228 | # falls back to nodeid | |
227 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') |
|
229 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') | |
228 | end |
|
230 | end | |
229 |
|
231 | |||
230 | def test_tags |
|
232 | def test_tags | |
231 | assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags |
|
233 | assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags | |
232 | end |
|
234 | end | |
233 |
|
235 | |||
234 | def test_tagmap |
|
236 | def test_tagmap | |
235 | tm = { |
|
237 | tm = { | |
236 | @tag_char_1 => 'adf805632193', |
|
238 | @tag_char_1 => 'adf805632193', | |
237 | 'tag_test.00' => '6987191f453a', |
|
239 | 'tag_test.00' => '6987191f453a', | |
238 | 'tag-init-revision' => '0885933ad4f6', |
|
240 | 'tag-init-revision' => '0885933ad4f6', | |
239 | } |
|
241 | } | |
240 | assert_equal tm, @adapter.tagmap |
|
242 | assert_equal tm, @adapter.tagmap | |
241 | end |
|
243 | end | |
242 |
|
244 | |||
243 | def test_branches |
|
245 | def test_branches | |
244 | assert_equal [ |
|
246 | assert_equal [ | |
245 | 'default', |
|
247 | 'default', | |
246 | 'branch (1)[2]&,%.-3_4', |
|
|||
247 | @branch_char_1, |
|
248 | @branch_char_1, | |
|
249 | 'branch (1)[2]&,%.-3_4', | |||
|
250 | @branch_char_0, | |||
248 | 'test_branch.latin-1', |
|
251 | 'test_branch.latin-1', | |
249 | 'test-branch-00', |
|
252 | 'test-branch-00', | |
250 | ], @adapter.branches |
|
253 | ], @adapter.branches | |
251 | end |
|
254 | end | |
252 |
|
255 | |||
253 | def test_branchmap |
|
256 | def test_branchmap | |
254 | bm = { |
|
257 | bm = { | |
255 | 'default' => '3ae45e2d177d', |
|
258 | 'default' => '3ae45e2d177d', | |
256 | 'test_branch.latin-1' => 'c2ffe7da686a', |
|
259 | 'test_branch.latin-1' => 'c2ffe7da686a', | |
257 | 'branch (1)[2]&,%.-3_4' => 'afc61e85bde7', |
|
260 | 'branch (1)[2]&,%.-3_4' => 'afc61e85bde7', | |
258 | 'test-branch-00' => '3a330eb32958', |
|
261 | 'test-branch-00' => '3a330eb32958', | |
259 |
@branch_char_ |
|
262 | @branch_char_0 => 'c8d3e4887474', | |
|
263 | @branch_char_1 => '7bbf4c738e71', | |||
260 | } |
|
264 | } | |
261 | assert_equal bm, @adapter.branchmap |
|
265 | assert_equal bm, @adapter.branchmap | |
262 | end |
|
266 | end | |
263 |
|
267 | |||
264 | def test_path_space |
|
268 | def test_path_space | |
265 | p = 'README (1)[2]&,%.-3_4' |
|
269 | p = 'README (1)[2]&,%.-3_4' | |
266 | [15, '933ca60293d7'].each do |r1| |
|
270 | [15, '933ca60293d7'].each do |r1| | |
267 | assert @adapter.diff(p, r1) |
|
271 | assert @adapter.diff(p, r1) | |
268 | assert @adapter.cat(p, r1) |
|
272 | assert @adapter.cat(p, r1) | |
269 | assert_equal 1, @adapter.annotate(p, r1).lines.length |
|
273 | assert_equal 1, @adapter.annotate(p, r1).lines.length | |
270 | [25, 'afc61e85bde7'].each do |r2| |
|
274 | [25, 'afc61e85bde7'].each do |r2| | |
271 | assert @adapter.diff(p, r1, r2) |
|
275 | assert @adapter.diff(p, r1, r2) | |
272 | end |
|
276 | end | |
273 | end |
|
277 | end | |
274 | end |
|
278 | end | |
275 |
|
279 | |||
276 | private |
|
280 | private | |
277 |
|
281 | |||
278 | def test_hgversion_for(hgversion, version) |
|
282 | def test_hgversion_for(hgversion, version) | |
279 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) |
|
283 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) | |
280 | assert_equal version, @adapter.class.hgversion |
|
284 | assert_equal version, @adapter.class.hgversion | |
281 | end |
|
285 | end | |
282 |
|
286 | |||
283 | def test_template_path_for(version, template) |
|
287 | def test_template_path_for(version, template) | |
284 | assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", |
|
288 | assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", | |
285 | @adapter.class.template_path_for(version) |
|
289 | @adapter.class.template_path_for(version) | |
286 | assert File.exist?(@adapter.class.template_path_for(version)) |
|
290 | assert File.exist?(@adapter.class.template_path_for(version)) | |
287 | end |
|
291 | end | |
288 | else |
|
292 | else | |
289 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
293 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
290 | def test_fake; assert true end |
|
294 | def test_fake; assert true end | |
291 | end |
|
295 | end | |
292 | end |
|
296 | end | |
293 |
|
297 | |||
294 | rescue LoadError |
|
298 | rescue LoadError | |
295 | class MercurialMochaFake < ActiveSupport::TestCase |
|
299 | class MercurialMochaFake < ActiveSupport::TestCase | |
296 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
300 | def test_fake; assert(false, "Requires mocha to run those tests") end | |
297 | end |
|
301 | end | |
298 | end |
|
302 | end | |
299 |
|
303 |
@@ -1,259 +1,259 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 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 |
|
19 | |||
20 | class RepositoryMercurialTest < ActiveSupport::TestCase |
|
20 | class RepositoryMercurialTest < ActiveSupport::TestCase | |
21 | fixtures :projects |
|
21 | fixtures :projects | |
22 |
|
22 | |||
23 | # No '..' in the repository path |
|
23 | # No '..' in the repository path | |
24 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' |
|
24 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' | |
25 |
|
25 | |||
26 | CHAR_1_HEX = "\xc3\x9c" |
|
26 | CHAR_1_HEX = "\xc3\x9c" | |
27 |
|
27 | |||
28 | def setup |
|
28 | def setup | |
29 | @project = Project.find(3) |
|
29 | @project = Project.find(3) | |
30 | @repository = Repository::Mercurial.create( |
|
30 | @repository = Repository::Mercurial.create( | |
31 | :project => @project, |
|
31 | :project => @project, | |
32 | :url => REPOSITORY_PATH, |
|
32 | :url => REPOSITORY_PATH, | |
33 | :path_encoding => 'ISO-8859-1' |
|
33 | :path_encoding => 'ISO-8859-1' | |
34 | ) |
|
34 | ) | |
35 | assert @repository |
|
35 | assert @repository | |
36 | @char_1 = CHAR_1_HEX.dup |
|
36 | @char_1 = CHAR_1_HEX.dup | |
37 | if @char_1.respond_to?(:force_encoding) |
|
37 | if @char_1.respond_to?(:force_encoding) | |
38 | @char_1.force_encoding('UTF-8') |
|
38 | @char_1.force_encoding('UTF-8') | |
39 | end |
|
39 | end | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | if File.directory?(REPOSITORY_PATH) |
|
42 | if File.directory?(REPOSITORY_PATH) | |
43 | def test_fetch_changesets_from_scratch |
|
43 | def test_fetch_changesets_from_scratch | |
44 | @repository.fetch_changesets |
|
44 | @repository.fetch_changesets | |
45 | @repository.reload |
|
45 | @repository.reload | |
46 |
assert_equal 2 |
|
46 | assert_equal 29, @repository.changesets.count | |
47 |
assert_equal 3 |
|
47 | assert_equal 37, @repository.changes.count | |
48 | assert_equal "Initial import.\nThe repository contains 3 files.", |
|
48 | assert_equal "Initial import.\nThe repository contains 3 files.", | |
49 | @repository.changesets.find_by_revision('0').comments |
|
49 | @repository.changesets.find_by_revision('0').comments | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def test_fetch_changesets_incremental |
|
52 | def test_fetch_changesets_incremental | |
53 | @repository.fetch_changesets |
|
53 | @repository.fetch_changesets | |
54 | # Remove changesets with revision > 2 |
|
54 | # Remove changesets with revision > 2 | |
55 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} |
|
55 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} | |
56 | @repository.reload |
|
56 | @repository.reload | |
57 | assert_equal 3, @repository.changesets.count |
|
57 | assert_equal 3, @repository.changesets.count | |
58 |
|
58 | |||
59 | @repository.fetch_changesets |
|
59 | @repository.fetch_changesets | |
60 |
assert_equal 2 |
|
60 | assert_equal 29, @repository.changesets.count | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def test_isodatesec |
|
63 | def test_isodatesec | |
64 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher |
|
64 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher | |
65 | if @repository.scm.class.client_version_above?([1, 0]) |
|
65 | if @repository.scm.class.client_version_above?([1, 0]) | |
66 | @repository.fetch_changesets |
|
66 | @repository.fetch_changesets | |
67 | @repository.reload |
|
67 | @repository.reload | |
68 | rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) |
|
68 | rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) | |
69 | assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on |
|
69 | assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on | |
70 | end |
|
70 | end | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def test_changeset_order_by_revision |
|
73 | def test_changeset_order_by_revision | |
74 | @repository.fetch_changesets |
|
74 | @repository.fetch_changesets | |
75 | @repository.reload |
|
75 | @repository.reload | |
76 |
|
76 | |||
77 | c0 = @repository.latest_changeset |
|
77 | c0 = @repository.latest_changeset | |
78 | c1 = @repository.changesets.find_by_revision('0') |
|
78 | c1 = @repository.changesets.find_by_revision('0') | |
79 | # sorted by revision (id), not by date |
|
79 | # sorted by revision (id), not by date | |
80 | assert c0.revision.to_i > c1.revision.to_i |
|
80 | assert c0.revision.to_i > c1.revision.to_i | |
81 | assert c0.committed_on < c1.committed_on |
|
81 | assert c0.committed_on < c1.committed_on | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def test_latest_changesets |
|
84 | def test_latest_changesets | |
85 | @repository.fetch_changesets |
|
85 | @repository.fetch_changesets | |
86 | @repository.reload |
|
86 | @repository.reload | |
87 |
|
87 | |||
88 | # with_limit |
|
88 | # with_limit | |
89 | changesets = @repository.latest_changesets('', nil, 2) |
|
89 | changesets = @repository.latest_changesets('', nil, 2) | |
90 | assert_equal @repository.latest_changesets('', nil)[0, 2], changesets |
|
90 | assert_equal @repository.latest_changesets('', nil)[0, 2], changesets | |
91 |
|
91 | |||
92 | # with_filepath |
|
92 | # with_filepath | |
93 | changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil) |
|
93 | changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil) | |
94 | assert_equal %w|11 10 9|, changesets.collect(&:revision) |
|
94 | assert_equal %w|11 10 9|, changesets.collect(&:revision) | |
95 |
|
95 | |||
96 | changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil) |
|
96 | changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil) | |
97 | assert_equal %w|12 9|, changesets.collect(&:revision) |
|
97 | assert_equal %w|12 9|, changesets.collect(&:revision) | |
98 | end |
|
98 | end | |
99 |
|
99 | |||
100 | def test_copied_files |
|
100 | def test_copied_files | |
101 | @repository.fetch_changesets |
|
101 | @repository.fetch_changesets | |
102 | @repository.reload |
|
102 | @repository.reload | |
103 |
|
103 | |||
104 | cs1 = @repository.changesets.find_by_revision('13') |
|
104 | cs1 = @repository.changesets.find_by_revision('13') | |
105 | assert_not_nil cs1 |
|
105 | assert_not_nil cs1 | |
106 | c1 = cs1.changes.sort_by(&:path) |
|
106 | c1 = cs1.changes.sort_by(&:path) | |
107 | assert_equal 2, c1.size |
|
107 | assert_equal 2, c1.size | |
108 |
|
108 | |||
109 | assert_equal 'A', c1[0].action |
|
109 | assert_equal 'A', c1[0].action | |
110 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path |
|
110 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path | |
111 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path |
|
111 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path | |
112 |
|
112 | |||
113 | assert_equal 'A', c1[1].action |
|
113 | assert_equal 'A', c1[1].action | |
114 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path |
|
114 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path | |
115 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path |
|
115 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path | |
116 |
|
116 | |||
117 | cs2 = @repository.changesets.find_by_revision('15') |
|
117 | cs2 = @repository.changesets.find_by_revision('15') | |
118 | c2 = cs2.changes |
|
118 | c2 = cs2.changes | |
119 | assert_equal 1, c2.size |
|
119 | assert_equal 1, c2.size | |
120 |
|
120 | |||
121 | assert_equal 'A', c2[0].action |
|
121 | assert_equal 'A', c2[0].action | |
122 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path |
|
122 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path | |
123 | assert_equal '/README', c2[0].from_path |
|
123 | assert_equal '/README', c2[0].from_path | |
124 |
|
124 | |||
125 | cs3 = @repository.changesets.find_by_revision('19') |
|
125 | cs3 = @repository.changesets.find_by_revision('19') | |
126 | c3 = cs3.changes |
|
126 | c3 = cs3.changes | |
127 | assert_equal 1, c3.size |
|
127 | assert_equal 1, c3.size | |
128 | assert_equal 'A', c3[0].action |
|
128 | assert_equal 'A', c3[0].action | |
129 | assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path |
|
129 | assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path | |
130 | assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path |
|
130 | assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path | |
131 | end |
|
131 | end | |
132 |
|
132 | |||
133 | def test_find_changeset_by_name |
|
133 | def test_find_changeset_by_name | |
134 | @repository.fetch_changesets |
|
134 | @repository.fetch_changesets | |
135 | @repository.reload |
|
135 | @repository.reload | |
136 | %w|2 400bb8672109 400|.each do |r| |
|
136 | %w|2 400bb8672109 400|.each do |r| | |
137 | assert_equal '2', @repository.find_changeset_by_name(r).revision |
|
137 | assert_equal '2', @repository.find_changeset_by_name(r).revision | |
138 | end |
|
138 | end | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def test_find_changeset_by_invalid_name |
|
141 | def test_find_changeset_by_invalid_name | |
142 | @repository.fetch_changesets |
|
142 | @repository.fetch_changesets | |
143 | @repository.reload |
|
143 | @repository.reload | |
144 | assert_nil @repository.find_changeset_by_name('100000') |
|
144 | assert_nil @repository.find_changeset_by_name('100000') | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | def test_identifier |
|
147 | def test_identifier | |
148 | @repository.fetch_changesets |
|
148 | @repository.fetch_changesets | |
149 | @repository.reload |
|
149 | @repository.reload | |
150 | c = @repository.changesets.find_by_revision('2') |
|
150 | c = @repository.changesets.find_by_revision('2') | |
151 | assert_equal c.scmid, c.identifier |
|
151 | assert_equal c.scmid, c.identifier | |
152 | end |
|
152 | end | |
153 |
|
153 | |||
154 | def test_format_identifier |
|
154 | def test_format_identifier | |
155 | @repository.fetch_changesets |
|
155 | @repository.fetch_changesets | |
156 | @repository.reload |
|
156 | @repository.reload | |
157 | c = @repository.changesets.find_by_revision('2') |
|
157 | c = @repository.changesets.find_by_revision('2') | |
158 | assert_equal '2:400bb8672109', c.format_identifier |
|
158 | assert_equal '2:400bb8672109', c.format_identifier | |
159 | end |
|
159 | end | |
160 |
|
160 | |||
161 | def test_find_changeset_by_empty_name |
|
161 | def test_find_changeset_by_empty_name | |
162 | @repository.fetch_changesets |
|
162 | @repository.fetch_changesets | |
163 | @repository.reload |
|
163 | @repository.reload | |
164 | ['', ' ', nil].each do |r| |
|
164 | ['', ' ', nil].each do |r| | |
165 | assert_nil @repository.find_changeset_by_name(r) |
|
165 | assert_nil @repository.find_changeset_by_name(r) | |
166 | end |
|
166 | end | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | def test_activities |
|
169 | def test_activities | |
170 | c = Changeset.new(:repository => @repository, |
|
170 | c = Changeset.new(:repository => @repository, | |
171 | :committed_on => Time.now, |
|
171 | :committed_on => Time.now, | |
172 | :revision => '123', |
|
172 | :revision => '123', | |
173 | :scmid => 'abc400bb8672', |
|
173 | :scmid => 'abc400bb8672', | |
174 | :comments => 'test') |
|
174 | :comments => 'test') | |
175 | assert c.event_title.include?('123:abc400bb8672:') |
|
175 | assert c.event_title.include?('123:abc400bb8672:') | |
176 | assert_equal 'abc400bb8672', c.event_url[:rev] |
|
176 | assert_equal 'abc400bb8672', c.event_url[:rev] | |
177 | end |
|
177 | end | |
178 |
|
178 | |||
179 | def test_latest_changesets_with_limit |
|
179 | def test_latest_changesets_with_limit | |
180 | @repository.fetch_changesets |
|
180 | @repository.fetch_changesets | |
181 | @repository.reload |
|
181 | @repository.reload | |
182 | changesets = @repository.latest_changesets('', nil, 2) |
|
182 | changesets = @repository.latest_changesets('', nil, 2) | |
183 | assert_equal @repository.latest_changesets('', nil)[0, 2], changesets |
|
183 | assert_equal @repository.latest_changesets('', nil)[0, 2], changesets | |
184 | end |
|
184 | end | |
185 |
|
185 | |||
186 | def test_latest_changesets_with_filepath |
|
186 | def test_latest_changesets_with_filepath | |
187 | @repository.fetch_changesets |
|
187 | @repository.fetch_changesets | |
188 | @repository.reload |
|
188 | @repository.reload | |
189 | changesets = @repository.latest_changesets('README', nil) |
|
189 | changesets = @repository.latest_changesets('README', nil) | |
190 |
assert_equal %w|2 |
|
190 | assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision) | |
191 |
|
191 | |||
192 | path = 'sql_escape/percent%dir/percent%file1.txt' |
|
192 | path = 'sql_escape/percent%dir/percent%file1.txt' | |
193 | changesets = @repository.latest_changesets(path, nil) |
|
193 | changesets = @repository.latest_changesets(path, nil) | |
194 | assert_equal %w|11 10 9|, changesets.collect(&:revision) |
|
194 | assert_equal %w|11 10 9|, changesets.collect(&:revision) | |
195 |
|
195 | |||
196 | path = 'sql_escape/underscore_dir/understrike_file.txt' |
|
196 | path = 'sql_escape/underscore_dir/understrike_file.txt' | |
197 | changesets = @repository.latest_changesets(path, nil) |
|
197 | changesets = @repository.latest_changesets(path, nil) | |
198 | assert_equal %w|12 9|, changesets.collect(&:revision) |
|
198 | assert_equal %w|12 9|, changesets.collect(&:revision) | |
199 | end |
|
199 | end | |
200 |
|
200 | |||
201 | def test_latest_changesets_with_dirpath |
|
201 | def test_latest_changesets_with_dirpath | |
202 | @repository.fetch_changesets |
|
202 | @repository.fetch_changesets | |
203 | @repository.reload |
|
203 | @repository.reload | |
204 | changesets = @repository.latest_changesets('images', nil) |
|
204 | changesets = @repository.latest_changesets('images', nil) | |
205 | assert_equal %w|1 0|, changesets.collect(&:revision) |
|
205 | assert_equal %w|1 0|, changesets.collect(&:revision) | |
206 |
|
206 | |||
207 | path = 'sql_escape/percent%dir' |
|
207 | path = 'sql_escape/percent%dir' | |
208 | changesets = @repository.latest_changesets(path, nil) |
|
208 | changesets = @repository.latest_changesets(path, nil) | |
209 | assert_equal %w|13 11 10 9|, changesets.collect(&:revision) |
|
209 | assert_equal %w|13 11 10 9|, changesets.collect(&:revision) | |
210 |
|
210 | |||
211 | path = 'sql_escape/underscore_dir' |
|
211 | path = 'sql_escape/underscore_dir' | |
212 | changesets = @repository.latest_changesets(path, nil) |
|
212 | changesets = @repository.latest_changesets(path, nil) | |
213 | assert_equal %w|13 12 9|, changesets.collect(&:revision) |
|
213 | assert_equal %w|13 12 9|, changesets.collect(&:revision) | |
214 | end |
|
214 | end | |
215 |
|
215 | |||
216 | def test_previous |
|
216 | def test_previous | |
217 | @repository.fetch_changesets |
|
217 | @repository.fetch_changesets | |
218 | @repository.reload |
|
218 | @repository.reload | |
219 |
%w|2 |
|
219 | %w|28 3ae45e2d177d 3ae45|.each do |r1| | |
220 | changeset = @repository.find_changeset_by_name(r1) |
|
220 | changeset = @repository.find_changeset_by_name(r1) | |
221 |
%w|2 |
|
221 | %w|27 7bbf4c738e71 7bbf|.each do |r2| | |
222 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
|
222 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous | |
223 | end |
|
223 | end | |
224 | end |
|
224 | end | |
225 | end |
|
225 | end | |
226 |
|
226 | |||
227 | def test_previous_nil |
|
227 | def test_previous_nil | |
228 | @repository.fetch_changesets |
|
228 | @repository.fetch_changesets | |
229 | @repository.reload |
|
229 | @repository.reload | |
230 | %w|0 0885933ad4f6 0885|.each do |r1| |
|
230 | %w|0 0885933ad4f6 0885|.each do |r1| | |
231 | changeset = @repository.find_changeset_by_name(r1) |
|
231 | changeset = @repository.find_changeset_by_name(r1) | |
232 | assert_nil changeset.previous |
|
232 | assert_nil changeset.previous | |
233 | end |
|
233 | end | |
234 | end |
|
234 | end | |
235 |
|
235 | |||
236 | def test_next |
|
236 | def test_next | |
237 | @repository.fetch_changesets |
|
237 | @repository.fetch_changesets | |
238 | @repository.reload |
|
238 | @repository.reload | |
239 |
%w|2 |
|
239 | %w|27 7bbf4c738e71 7bbf|.each do |r2| | |
240 | changeset = @repository.find_changeset_by_name(r2) |
|
240 | changeset = @repository.find_changeset_by_name(r2) | |
241 |
%w|2 |
|
241 | %w|28 3ae45e2d177d 3ae45|.each do |r1| | |
242 | assert_equal @repository.find_changeset_by_name(r1), changeset.next |
|
242 | assert_equal @repository.find_changeset_by_name(r1), changeset.next | |
243 | end |
|
243 | end | |
244 | end |
|
244 | end | |
245 | end |
|
245 | end | |
246 |
|
246 | |||
247 | def test_next_nil |
|
247 | def test_next_nil | |
248 | @repository.fetch_changesets |
|
248 | @repository.fetch_changesets | |
249 | @repository.reload |
|
249 | @repository.reload | |
250 |
%w|2 |
|
250 | %w|28 3ae45e2d177d 3ae45|.each do |r1| | |
251 | changeset = @repository.find_changeset_by_name(r1) |
|
251 | changeset = @repository.find_changeset_by_name(r1) | |
252 | assert_nil changeset.next |
|
252 | assert_nil changeset.next | |
253 | end |
|
253 | end | |
254 | end |
|
254 | end | |
255 | else |
|
255 | else | |
256 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
256 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
257 | def test_fake; assert true end |
|
257 | def test_fake; assert true end | |
258 | end |
|
258 | end | |
259 | end |
|
259 | end |
General Comments 0
You need to be logged in to leave comments.
Login now