@@ -1,223 +1,224 | |||||
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(:project => Project.find(3), :url => REPOSITORY_PATH) |
|
35 | @repository = Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH) | |
36 | assert @repository |
|
36 | assert @repository | |
|
37 | @diff_c_support = @repository.scm.class.client_version_above?([1, 2]) | |||
37 | end |
|
38 | end | |
38 |
|
39 | |||
39 | if File.directory?(REPOSITORY_PATH) |
|
40 | if File.directory?(REPOSITORY_PATH) | |
40 | def test_show |
|
41 | def test_show | |
41 | get :show, :id => 3 |
|
42 | get :show, :id => 3 | |
42 | assert_response :success |
|
43 | assert_response :success | |
43 | assert_template 'show' |
|
44 | assert_template 'show' | |
44 | assert_not_nil assigns(:entries) |
|
45 | assert_not_nil assigns(:entries) | |
45 | assert_not_nil assigns(:changesets) |
|
46 | assert_not_nil assigns(:changesets) | |
46 | end |
|
47 | end | |
47 |
|
48 | |||
48 | def test_show_root |
|
49 | def test_show_root | |
49 | get :show, :id => 3 |
|
50 | get :show, :id => 3 | |
50 | assert_response :success |
|
51 | assert_response :success | |
51 | assert_template 'show' |
|
52 | assert_template 'show' | |
52 | assert_not_nil assigns(:entries) |
|
53 | assert_not_nil assigns(:entries) | |
53 | assert_equal 4, assigns(:entries).size |
|
54 | assert_equal 4, assigns(:entries).size | |
54 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
55 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} | |
55 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
56 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} | |
56 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
57 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} | |
57 | end |
|
58 | end | |
58 |
|
59 | |||
59 | def test_show_directory |
|
60 | def test_show_directory | |
60 | get :show, :id => 3, :path => ['images'] |
|
61 | get :show, :id => 3, :path => ['images'] | |
61 | assert_response :success |
|
62 | assert_response :success | |
62 | assert_template 'show' |
|
63 | assert_template 'show' | |
63 | assert_not_nil assigns(:entries) |
|
64 | assert_not_nil assigns(:entries) | |
64 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
65 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
65 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
66 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
66 | assert_not_nil entry |
|
67 | assert_not_nil entry | |
67 | assert_equal 'file', entry.kind |
|
68 | assert_equal 'file', entry.kind | |
68 | assert_equal 'images/edit.png', entry.path |
|
69 | assert_equal 'images/edit.png', entry.path | |
69 | end |
|
70 | end | |
70 |
|
71 | |||
71 | def test_show_at_given_revision |
|
72 | def test_show_at_given_revision | |
72 | [0, '0', '0885933ad4f6'].each do |r1| |
|
73 | [0, '0', '0885933ad4f6'].each do |r1| | |
73 | get :show, :id => 3, :path => ['images'], :rev => r1 |
|
74 | get :show, :id => 3, :path => ['images'], :rev => r1 | |
74 | assert_response :success |
|
75 | assert_response :success | |
75 | assert_template 'show' |
|
76 | assert_template 'show' | |
76 | assert_not_nil assigns(:entries) |
|
77 | assert_not_nil assigns(:entries) | |
77 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
78 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |
78 | end |
|
79 | end | |
79 | end |
|
80 | end | |
80 |
|
81 | |||
81 | def test_show_directory_sql_escape_percent |
|
82 | def test_show_directory_sql_escape_percent | |
82 | [13, '13', '3a330eb32958'].each do |r1| |
|
83 | [13, '13', '3a330eb32958'].each do |r1| | |
83 | get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1 |
|
84 | get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1 | |
84 | assert_response :success |
|
85 | assert_response :success | |
85 | assert_template 'show' |
|
86 | assert_template 'show' | |
86 |
|
87 | |||
87 | assert_not_nil assigns(:entries) |
|
88 | assert_not_nil assigns(:entries) | |
88 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name) |
|
89 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name) | |
89 | changesets = assigns(:changesets) |
|
90 | changesets = assigns(:changesets) | |
90 |
|
91 | |||
91 | ## This is not yet implemented. |
|
92 | ## This is not yet implemented. | |
92 | # assert_not_nil changesets |
|
93 | # assert_not_nil changesets | |
93 | # assert_equal %w(13 11 10 9), changesets.collect(&:revision) |
|
94 | # assert_equal %w(13 11 10 9), changesets.collect(&:revision) | |
94 | end |
|
95 | end | |
95 | end |
|
96 | end | |
96 |
|
97 | |||
97 | def test_changes |
|
98 | def test_changes | |
98 | get :changes, :id => 3, :path => ['images', 'edit.png'] |
|
99 | get :changes, :id => 3, :path => ['images', 'edit.png'] | |
99 | assert_response :success |
|
100 | assert_response :success | |
100 | assert_template 'changes' |
|
101 | assert_template 'changes' | |
101 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
102 | assert_tag :tag => 'h2', :content => 'edit.png' | |
102 | end |
|
103 | end | |
103 |
|
104 | |||
104 | def test_entry_show |
|
105 | def test_entry_show | |
105 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] |
|
106 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] | |
106 | assert_response :success |
|
107 | assert_response :success | |
107 | assert_template 'entry' |
|
108 | assert_template 'entry' | |
108 | # Line 10 |
|
109 | # Line 10 | |
109 | assert_tag :tag => 'th', |
|
110 | assert_tag :tag => 'th', | |
110 | :content => '10', |
|
111 | :content => '10', | |
111 | :attributes => { :class => 'line-num' }, |
|
112 | :attributes => { :class => 'line-num' }, | |
112 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
|
113 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } | |
113 | end |
|
114 | end | |
114 |
|
115 | |||
115 | def test_entry_download |
|
116 | def test_entry_download | |
116 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' |
|
117 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' | |
117 | assert_response :success |
|
118 | assert_response :success | |
118 | # File content |
|
119 | # File content | |
119 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
|
120 | assert @response.body.include?('WITHOUT ANY WARRANTY') | |
120 | end |
|
121 | end | |
121 |
|
122 | |||
122 | def test_directory_entry |
|
123 | def test_directory_entry | |
123 | get :entry, :id => 3, :path => ['sources'] |
|
124 | get :entry, :id => 3, :path => ['sources'] | |
124 | assert_response :success |
|
125 | assert_response :success | |
125 | assert_template 'show' |
|
126 | assert_template 'show' | |
126 | assert_not_nil assigns(:entry) |
|
127 | assert_not_nil assigns(:entry) | |
127 | assert_equal 'sources', assigns(:entry).name |
|
128 | assert_equal 'sources', assigns(:entry).name | |
128 | end |
|
129 | end | |
129 |
|
130 | |||
130 | def test_diff |
|
131 | def test_diff | |
131 | @repository.fetch_changesets |
|
132 | @repository.fetch_changesets | |
132 | @repository.reload |
|
133 | @repository.reload | |
133 |
|
134 | |||
134 | [4, '4', 'def6d2f1254a'].each do |r1| |
|
135 | [4, '4', 'def6d2f1254a'].each do |r1| | |
135 | # Full diff of changeset 4 |
|
136 | # Full diff of changeset 4 | |
136 | get :diff, :id => 3, :rev => r1 |
|
137 | get :diff, :id => 3, :rev => r1 | |
137 | assert_response :success |
|
138 | assert_response :success | |
138 | assert_template 'diff' |
|
139 | assert_template 'diff' | |
139 |
|
140 | |||
140 | if @repository.scm.class.client_version_above?([1, 2]) |
|
141 | if @diff_c_support | |
141 | # Line 22 removed |
|
142 | # Line 22 removed | |
142 | assert_tag :tag => 'th', |
|
143 | assert_tag :tag => 'th', | |
143 | :content => '22', |
|
144 | :content => '22', | |
144 | :sibling => { :tag => 'td', |
|
145 | :sibling => { :tag => 'td', | |
145 | :attributes => { :class => /diff_out/ }, |
|
146 | :attributes => { :class => /diff_out/ }, | |
146 | :content => /def remove/ } |
|
147 | :content => /def remove/ } | |
147 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ |
|
148 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ | |
148 | end |
|
149 | end | |
149 | end |
|
150 | end | |
150 | end |
|
151 | end | |
151 |
|
152 | |||
152 | def test_diff_two_revs |
|
153 | def test_diff_two_revs | |
153 | @repository.fetch_changesets |
|
154 | @repository.fetch_changesets | |
154 | @repository.reload |
|
155 | @repository.reload | |
155 |
|
156 | |||
156 | [2, '400bb8672109', '400', 400].each do |r1| |
|
157 | [2, '400bb8672109', '400', 400].each do |r1| | |
157 | [4, 'def6d2f1254a'].each do |r2| |
|
158 | [4, 'def6d2f1254a'].each do |r2| | |
158 | get :diff, :id => 3, :rev => r1, |
|
159 | get :diff, :id => 3, :rev => r1, | |
159 | :rev_to => r2 |
|
160 | :rev_to => r2 | |
160 | assert_response :success |
|
161 | assert_response :success | |
161 | assert_template 'diff' |
|
162 | assert_template 'diff' | |
162 |
|
163 | |||
163 | diff = assigns(:diff) |
|
164 | diff = assigns(:diff) | |
164 | assert_not_nil diff |
|
165 | assert_not_nil diff | |
165 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/ |
|
166 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/ | |
166 | end |
|
167 | end | |
167 | end |
|
168 | end | |
168 | end |
|
169 | end | |
169 |
|
170 | |||
170 | def test_annotate |
|
171 | def test_annotate | |
171 | get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] |
|
172 | get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] | |
172 | assert_response :success |
|
173 | assert_response :success | |
173 | assert_template 'annotate' |
|
174 | assert_template 'annotate' | |
174 | # Line 23, revision 4:def6d2f1254a |
|
175 | # Line 23, revision 4:def6d2f1254a | |
175 | assert_tag :tag => 'th', |
|
176 | assert_tag :tag => 'th', | |
176 | :content => '23', |
|
177 | :content => '23', | |
177 | :attributes => { :class => 'line-num' }, |
|
178 | :attributes => { :class => 'line-num' }, | |
178 | :sibling => |
|
179 | :sibling => | |
179 | { |
|
180 | { | |
180 | :tag => 'td', |
|
181 | :tag => 'td', | |
181 | :attributes => { :class => 'revision' }, |
|
182 | :attributes => { :class => 'revision' }, | |
182 | :child => { :tag => 'a', :content => '4:def6d2f1254a' } |
|
183 | :child => { :tag => 'a', :content => '4:def6d2f1254a' } | |
183 | } |
|
184 | } | |
184 | assert_tag :tag => 'th', |
|
185 | assert_tag :tag => 'th', | |
185 | :content => '23', |
|
186 | :content => '23', | |
186 | :attributes => { :class => 'line-num' }, |
|
187 | :attributes => { :class => 'line-num' }, | |
187 | :sibling => |
|
188 | :sibling => | |
188 | { |
|
189 | { | |
189 | :tag => 'td' , |
|
190 | :tag => 'td' , | |
190 | :content => 'jsmith' , |
|
191 | :content => 'jsmith' , | |
191 | :attributes => { :class => 'author' }, |
|
192 | :attributes => { :class => 'author' }, | |
192 | } |
|
193 | } | |
193 | assert_tag :tag => 'th', |
|
194 | assert_tag :tag => 'th', | |
194 | :content => '23', |
|
195 | :content => '23', | |
195 | :attributes => { :class => 'line-num' }, |
|
196 | :attributes => { :class => 'line-num' }, | |
196 | :sibling => { :tag => 'td', :content => /watcher =/ } |
|
197 | :sibling => { :tag => 'td', :content => /watcher =/ } | |
197 | end |
|
198 | end | |
198 |
|
199 | |||
199 | def test_annotate_at_given_revision |
|
200 | def test_annotate_at_given_revision | |
200 | @repository.fetch_changesets |
|
201 | @repository.fetch_changesets | |
201 | @repository.reload |
|
202 | @repository.reload | |
202 | [2, '400bb8672109', '400', 400].each do |r1| |
|
203 | [2, '400bb8672109', '400', 400].each do |r1| | |
203 | get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb'] |
|
204 | get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb'] | |
204 | assert_response :success |
|
205 | assert_response :success | |
205 | assert_template 'annotate' |
|
206 | assert_template 'annotate' | |
206 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ |
|
207 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ | |
207 | end |
|
208 | end | |
208 | end |
|
209 | end | |
209 |
|
210 | |||
210 | def test_empty_revision |
|
211 | def test_empty_revision | |
211 | @repository.fetch_changesets |
|
212 | @repository.fetch_changesets | |
212 | @repository.reload |
|
213 | @repository.reload | |
213 | ['', ' ', nil].each do |r| |
|
214 | ['', ' ', nil].each do |r| | |
214 | get :revision, :id => 3, :rev => r |
|
215 | get :revision, :id => 3, :rev => r | |
215 | assert_response 404 |
|
216 | assert_response 404 | |
216 | assert_error_tag :content => /was not found/ |
|
217 | assert_error_tag :content => /was not found/ | |
217 | end |
|
218 | end | |
218 | end |
|
219 | end | |
219 | else |
|
220 | else | |
220 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" |
|
221 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" | |
221 | def test_fake; assert true end |
|
222 | def test_fake; assert true end | |
222 | end |
|
223 | end | |
223 | end |
|
224 | end |
@@ -1,191 +1,192 | |||||
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 | if File.directory?(REPOSITORY_PATH) |
|
13 | if File.directory?(REPOSITORY_PATH) | |
14 | def setup |
|
14 | def setup | |
15 | @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH) |
|
15 | @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH) | |
|
16 | @diff_c_support = @adapter.class.client_version_above?([1, 2]) | |||
16 | end |
|
17 | end | |
17 |
|
18 | |||
18 | def test_hgversion |
|
19 | def test_hgversion | |
19 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], |
|
20 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], | |
20 | "Mercurial Distributed SCM (1.0)\n" => [1,0], |
|
21 | "Mercurial Distributed SCM (1.0)\n" => [1,0], | |
21 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, |
|
22 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, | |
22 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], |
|
23 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], | |
23 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, |
|
24 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, | |
24 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], |
|
25 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], | |
25 | "(1.6)\n(1.7)\n(1.8)" => [1,6], |
|
26 | "(1.6)\n(1.7)\n(1.8)" => [1,6], | |
26 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} |
|
27 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} | |
27 |
|
28 | |||
28 | to_test.each do |s, v| |
|
29 | to_test.each do |s, v| | |
29 | test_hgversion_for(s, v) |
|
30 | test_hgversion_for(s, v) | |
30 | end |
|
31 | end | |
31 | end |
|
32 | end | |
32 |
|
33 | |||
33 | def test_template_path |
|
34 | def test_template_path | |
34 | to_test = { [0,9,5] => "0.9.5", |
|
35 | to_test = { [0,9,5] => "0.9.5", | |
35 | [1,0] => "1.0", |
|
36 | [1,0] => "1.0", | |
36 | [] => "1.0", |
|
37 | [] => "1.0", | |
37 | [1,0,1] => "1.0", |
|
38 | [1,0,1] => "1.0", | |
38 | [1,7] => "1.0", |
|
39 | [1,7] => "1.0", | |
39 | [1,7,1] => "1.0" } |
|
40 | [1,7,1] => "1.0" } | |
40 | to_test.each do |v, template| |
|
41 | to_test.each do |v, template| | |
41 | test_template_path_for(v, template) |
|
42 | test_template_path_for(v, template) | |
42 | end |
|
43 | end | |
43 | end |
|
44 | end | |
44 |
|
45 | |||
45 | def test_info |
|
46 | def test_info | |
46 | [REPOSITORY_PATH, REPOSITORY_PATH + "/", |
|
47 | [REPOSITORY_PATH, REPOSITORY_PATH + "/", | |
47 | REPOSITORY_PATH + "//"].each do |repo| |
|
48 | REPOSITORY_PATH + "//"].each do |repo| | |
48 | adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) |
|
49 | adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) | |
49 | assert_equal REPOSITORY_PATH, adp.info.root_url |
|
50 | assert_equal REPOSITORY_PATH, adp.info.root_url | |
50 | assert_equal '16', adp.info.lastrev.revision |
|
51 | assert_equal '16', adp.info.lastrev.revision | |
51 | assert_equal '4cddb4e45f52',adp.info.lastrev.scmid |
|
52 | assert_equal '4cddb4e45f52',adp.info.lastrev.scmid | |
52 | end |
|
53 | end | |
53 | end |
|
54 | end | |
54 |
|
55 | |||
55 | def test_revisions |
|
56 | def test_revisions | |
56 | revisions = @adapter.revisions(nil, 2, 4) |
|
57 | revisions = @adapter.revisions(nil, 2, 4) | |
57 | assert_equal 3, revisions.size |
|
58 | assert_equal 3, revisions.size | |
58 | assert_equal '2', revisions[0].revision |
|
59 | assert_equal '2', revisions[0].revision | |
59 | assert_equal '400bb8672109', revisions[0].scmid |
|
60 | assert_equal '400bb8672109', revisions[0].scmid | |
60 | assert_equal '4', revisions[2].revision |
|
61 | assert_equal '4', revisions[2].revision | |
61 | assert_equal 'def6d2f1254a', revisions[2].scmid |
|
62 | assert_equal 'def6d2f1254a', revisions[2].scmid | |
62 |
|
63 | |||
63 | revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) |
|
64 | revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) | |
64 | assert_equal 2, revisions.size |
|
65 | assert_equal 2, revisions.size | |
65 | assert_equal '2', revisions[0].revision |
|
66 | assert_equal '2', revisions[0].revision | |
66 | assert_equal '400bb8672109', revisions[0].scmid |
|
67 | assert_equal '400bb8672109', revisions[0].scmid | |
67 | end |
|
68 | end | |
68 |
|
69 | |||
69 | def test_diff |
|
70 | def test_diff | |
70 | if @adapter.class.client_version_above?([1, 2]) |
|
71 | if @adapter.class.client_version_above?([1, 2]) | |
71 | assert_nil @adapter.diff(nil, '100000') |
|
72 | assert_nil @adapter.diff(nil, '100000') | |
72 | end |
|
73 | end | |
73 | assert_nil @adapter.diff(nil, '100000', '200000') |
|
74 | assert_nil @adapter.diff(nil, '100000', '200000') | |
74 | [2, '400bb8672109', '400', 400].each do |r1| |
|
75 | [2, '400bb8672109', '400', 400].each do |r1| | |
75 | diff1 = @adapter.diff(nil, r1) |
|
76 | diff1 = @adapter.diff(nil, r1) | |
76 | if @adapter.class.client_version_above?([1, 2]) |
|
77 | if @diff_c_support | |
77 | assert_equal 28, diff1.size |
|
78 | assert_equal 28, diff1.size | |
78 | buf = diff1[24].gsub(/\r\n|\r|\n/, "") |
|
79 | buf = diff1[24].gsub(/\r\n|\r|\n/, "") | |
79 | assert_equal "+ return true unless klass.respond_to?('watched_by')", buf |
|
80 | assert_equal "+ return true unless klass.respond_to?('watched_by')", buf | |
80 | else |
|
81 | else | |
81 | assert_equal 0, diff1.size |
|
82 | assert_equal 0, diff1.size | |
82 | end |
|
83 | end | |
83 | [4, 'def6d2f1254a'].each do |r2| |
|
84 | [4, 'def6d2f1254a'].each do |r2| | |
84 | diff2 = @adapter.diff(nil,r1,r2) |
|
85 | diff2 = @adapter.diff(nil,r1,r2) | |
85 | assert_equal 49, diff2.size |
|
86 | assert_equal 49, diff2.size | |
86 | buf = diff2[41].gsub(/\r\n|\r|\n/, "") |
|
87 | buf = diff2[41].gsub(/\r\n|\r|\n/, "") | |
87 | assert_equal "+class WelcomeController < ApplicationController", buf |
|
88 | assert_equal "+class WelcomeController < ApplicationController", buf | |
88 | diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) |
|
89 | diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) | |
89 | assert_equal 20, diff3.size |
|
90 | assert_equal 20, diff3.size | |
90 | buf = diff3[12].gsub(/\r\n|\r|\n/, "") |
|
91 | buf = diff3[12].gsub(/\r\n|\r|\n/, "") | |
91 | assert_equal "+ @watched.remove_watcher(user)", buf |
|
92 | assert_equal "+ @watched.remove_watcher(user)", buf | |
92 | end |
|
93 | end | |
93 | end |
|
94 | end | |
94 | end |
|
95 | end | |
95 |
|
96 | |||
96 | def test_diff_made_by_revision |
|
97 | def test_diff_made_by_revision | |
97 | if @adapter.class.client_version_above?([1, 2]) |
|
98 | if @diff_c_support | |
98 | [16, '16', '4cddb4e45f52'].each do |r1| |
|
99 | [16, '16', '4cddb4e45f52'].each do |r1| | |
99 | diff1 = @adapter.diff(nil, r1) |
|
100 | diff1 = @adapter.diff(nil, r1) | |
100 | assert_equal 5, diff1.size |
|
101 | assert_equal 5, diff1.size | |
101 | buf = diff1[4].gsub(/\r\n|\r|\n/, "") |
|
102 | buf = diff1[4].gsub(/\r\n|\r|\n/, "") | |
102 | assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf |
|
103 | assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf | |
103 | end |
|
104 | end | |
104 | end |
|
105 | end | |
105 | end |
|
106 | end | |
106 |
|
107 | |||
107 | def test_cat |
|
108 | def test_cat | |
108 | [2, '400bb8672109', '400', 400].each do |r| |
|
109 | [2, '400bb8672109', '400', 400].each do |r| | |
109 | buf = @adapter.cat('sources/welcome_controller.rb', r) |
|
110 | buf = @adapter.cat('sources/welcome_controller.rb', r) | |
110 | assert buf |
|
111 | assert buf | |
111 | lines = buf.split("\r\n") |
|
112 | lines = buf.split("\r\n") | |
112 | assert_equal 25, lines.length |
|
113 | assert_equal 25, lines.length | |
113 | assert_equal 'class WelcomeController < ApplicationController', lines[17] |
|
114 | assert_equal 'class WelcomeController < ApplicationController', lines[17] | |
114 | end |
|
115 | end | |
115 | assert_nil @adapter.cat('sources/welcome_controller.rb') |
|
116 | assert_nil @adapter.cat('sources/welcome_controller.rb') | |
116 | end |
|
117 | end | |
117 |
|
118 | |||
118 | def test_annotate |
|
119 | def test_annotate | |
119 | assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines |
|
120 | assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines | |
120 | [2, '400bb8672109', '400', 400].each do |r| |
|
121 | [2, '400bb8672109', '400', 400].each do |r| | |
121 | ann = @adapter.annotate('sources/welcome_controller.rb', r) |
|
122 | ann = @adapter.annotate('sources/welcome_controller.rb', r) | |
122 | assert ann |
|
123 | assert ann | |
123 | assert_equal '1', ann.revisions[17].revision |
|
124 | assert_equal '1', ann.revisions[17].revision | |
124 | assert_equal '9d5b5b004199', ann.revisions[17].identifier |
|
125 | assert_equal '9d5b5b004199', ann.revisions[17].identifier | |
125 | assert_equal 'jsmith', ann.revisions[0].author |
|
126 | assert_equal 'jsmith', ann.revisions[0].author | |
126 | assert_equal 25, ann.lines.length |
|
127 | assert_equal 25, ann.lines.length | |
127 | assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] |
|
128 | assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] | |
128 | end |
|
129 | end | |
129 | end |
|
130 | end | |
130 |
|
131 | |||
131 | # TODO filesize etc. |
|
132 | # TODO filesize etc. | |
132 | def test_entries |
|
133 | def test_entries | |
133 | assert_nil @adapter.entries(nil, '100000') |
|
134 | assert_nil @adapter.entries(nil, '100000') | |
134 | [2, '400bb8672109', '400', 400].each do |r| |
|
135 | [2, '400bb8672109', '400', 400].each do |r| | |
135 | entries1 = @adapter.entries(nil, r) |
|
136 | entries1 = @adapter.entries(nil, r) | |
136 | assert entries1 |
|
137 | assert entries1 | |
137 | assert_equal 3, entries1.size |
|
138 | assert_equal 3, entries1.size | |
138 | assert_equal 'sources', entries1[1].name |
|
139 | assert_equal 'sources', entries1[1].name | |
139 | assert_equal 'sources', entries1[1].path |
|
140 | assert_equal 'sources', entries1[1].path | |
140 | assert_equal 'dir', entries1[1].kind |
|
141 | assert_equal 'dir', entries1[1].kind | |
141 | assert_equal 'README', entries1[2].name |
|
142 | assert_equal 'README', entries1[2].name | |
142 | assert_equal 'README', entries1[2].path |
|
143 | assert_equal 'README', entries1[2].path | |
143 | assert_equal 'file', entries1[2].kind |
|
144 | assert_equal 'file', entries1[2].kind | |
144 |
|
145 | |||
145 | entries2 = @adapter.entries('sources', r) |
|
146 | entries2 = @adapter.entries('sources', r) | |
146 | assert entries2 |
|
147 | assert entries2 | |
147 | assert_equal 2, entries2.size |
|
148 | assert_equal 2, entries2.size | |
148 | assert_equal 'watchers_controller.rb', entries2[0].name |
|
149 | assert_equal 'watchers_controller.rb', entries2[0].name | |
149 | assert_equal 'sources/watchers_controller.rb', entries2[0].path |
|
150 | assert_equal 'sources/watchers_controller.rb', entries2[0].path | |
150 | assert_equal 'file', entries2[0].kind |
|
151 | assert_equal 'file', entries2[0].kind | |
151 | assert_equal 'welcome_controller.rb', entries2[1].name |
|
152 | assert_equal 'welcome_controller.rb', entries2[1].name | |
152 | assert_equal 'sources/welcome_controller.rb', entries2[1].path |
|
153 | assert_equal 'sources/welcome_controller.rb', entries2[1].path | |
153 | assert_equal 'file', entries2[1].kind |
|
154 | assert_equal 'file', entries2[1].kind | |
154 | end |
|
155 | end | |
155 | end |
|
156 | end | |
156 |
|
157 | |||
157 | def test_access_by_nodeid |
|
158 | def test_access_by_nodeid | |
158 | path = 'sources/welcome_controller.rb' |
|
159 | path = 'sources/welcome_controller.rb' | |
159 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') |
|
160 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') | |
160 | end |
|
161 | end | |
161 |
|
162 | |||
162 | def test_access_by_fuzzy_nodeid |
|
163 | def test_access_by_fuzzy_nodeid | |
163 | path = 'sources/welcome_controller.rb' |
|
164 | path = 'sources/welcome_controller.rb' | |
164 | # falls back to nodeid |
|
165 | # falls back to nodeid | |
165 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') |
|
166 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') | |
166 | end |
|
167 | end | |
167 |
|
168 | |||
168 | private |
|
169 | private | |
169 |
|
170 | |||
170 | def test_hgversion_for(hgversion, version) |
|
171 | def test_hgversion_for(hgversion, version) | |
171 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) |
|
172 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) | |
172 | assert_equal version, @adapter.class.hgversion |
|
173 | assert_equal version, @adapter.class.hgversion | |
173 | end |
|
174 | end | |
174 |
|
175 | |||
175 | def test_template_path_for(version, template) |
|
176 | def test_template_path_for(version, template) | |
176 | assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", |
|
177 | assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", | |
177 | @adapter.class.template_path_for(version) |
|
178 | @adapter.class.template_path_for(version) | |
178 | assert File.exist?(@adapter.class.template_path_for(version)) |
|
179 | assert File.exist?(@adapter.class.template_path_for(version)) | |
179 | end |
|
180 | end | |
180 | else |
|
181 | else | |
181 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
182 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
182 | def test_fake; assert true end |
|
183 | def test_fake; assert true end | |
183 | end |
|
184 | end | |
184 | end |
|
185 | end | |
185 |
|
186 | |||
186 | rescue LoadError |
|
187 | rescue LoadError | |
187 | class MercurialMochaFake < ActiveSupport::TestCase |
|
188 | class MercurialMochaFake < ActiveSupport::TestCase | |
188 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
189 | def test_fake; assert(false, "Requires mocha to run those tests") end | |
189 | end |
|
190 | end | |
190 | end |
|
191 | end | |
191 |
|
192 |
General Comments 0
You need to be logged in to leave comments.
Login now