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