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