@@ -1,165 +1,186 | |||||
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(1) |
|
27 | @project = Project.find(1) | |
28 | @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH) |
|
28 | @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH) | |
29 | assert @repository |
|
29 | assert @repository | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
32 | if File.directory?(REPOSITORY_PATH) |
|
32 | if File.directory?(REPOSITORY_PATH) | |
33 | def test_fetch_changesets_from_scratch |
|
33 | def test_fetch_changesets_from_scratch | |
34 | @repository.fetch_changesets |
|
34 | @repository.fetch_changesets | |
35 | @repository.reload |
|
35 | @repository.reload | |
36 | assert_equal 17, @repository.changesets.count |
|
36 | assert_equal 17, @repository.changesets.count | |
37 | assert_equal 25, @repository.changes.count |
|
37 | assert_equal 25, @repository.changes.count | |
38 | assert_equal "Initial import.\nThe repository contains 3 files.", |
|
38 | assert_equal "Initial import.\nThe repository contains 3 files.", | |
39 | @repository.changesets.find_by_revision('0').comments |
|
39 | @repository.changesets.find_by_revision('0').comments | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def test_fetch_changesets_incremental |
|
42 | def test_fetch_changesets_incremental | |
43 | @repository.fetch_changesets |
|
43 | @repository.fetch_changesets | |
44 | # Remove changesets with revision > 2 |
|
44 | # Remove changesets with revision > 2 | |
45 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} |
|
45 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} | |
46 | @repository.reload |
|
46 | @repository.reload | |
47 | assert_equal 3, @repository.changesets.count |
|
47 | assert_equal 3, @repository.changesets.count | |
48 |
|
48 | |||
49 | @repository.fetch_changesets |
|
49 | @repository.fetch_changesets | |
50 | assert_equal 17, @repository.changesets.count |
|
50 | assert_equal 17, @repository.changesets.count | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_isodatesec |
|
53 | def test_isodatesec | |
54 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher |
|
54 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher | |
55 | if @repository.scm.class.client_version_above?([1, 0]) |
|
55 | if @repository.scm.class.client_version_above?([1, 0]) | |
56 | @repository.fetch_changesets |
|
56 | @repository.fetch_changesets | |
57 | @repository.reload |
|
57 | @repository.reload | |
58 | rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) |
|
58 | 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 |
|
59 | assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on | |
60 | end |
|
60 | end | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def test_changeset_order_by_revision |
|
63 | def test_changeset_order_by_revision | |
64 | @repository.fetch_changesets |
|
64 | @repository.fetch_changesets | |
65 | @repository.reload |
|
65 | @repository.reload | |
66 |
|
66 | |||
67 | c0 = @repository.latest_changeset |
|
67 | c0 = @repository.latest_changeset | |
68 | c1 = @repository.changesets.find_by_revision('0') |
|
68 | c1 = @repository.changesets.find_by_revision('0') | |
69 | # sorted by revision (id), not by date |
|
69 | # sorted by revision (id), not by date | |
70 | assert c0.revision.to_i > c1.revision.to_i |
|
70 | assert c0.revision.to_i > c1.revision.to_i | |
71 | assert c0.committed_on < c1.committed_on |
|
71 | assert c0.committed_on < c1.committed_on | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def test_latest_changesets |
|
74 | def test_latest_changesets | |
75 | @repository.fetch_changesets |
|
75 | @repository.fetch_changesets | |
76 | @repository.reload |
|
76 | @repository.reload | |
77 |
|
77 | |||
78 | # with_limit |
|
78 | # with_limit | |
79 | changesets = @repository.latest_changesets('', nil, 2) |
|
79 | changesets = @repository.latest_changesets('', nil, 2) | |
80 | assert_equal @repository.latest_changesets('', nil)[0, 2], changesets |
|
80 | assert_equal @repository.latest_changesets('', nil)[0, 2], changesets | |
81 |
|
81 | |||
82 | # with_filepath |
|
82 | # with_filepath | |
83 | changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil) |
|
83 | changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil) | |
84 | assert_equal %w|11 10 9|, changesets.collect(&:revision) |
|
84 | assert_equal %w|11 10 9|, changesets.collect(&:revision) | |
85 |
|
85 | |||
86 | changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil) |
|
86 | changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil) | |
87 | assert_equal %w|12 9|, changesets.collect(&:revision) |
|
87 | assert_equal %w|12 9|, changesets.collect(&:revision) | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | def test_copied_files |
|
90 | def test_copied_files | |
91 | @repository.fetch_changesets |
|
91 | @repository.fetch_changesets | |
92 | @repository.reload |
|
92 | @repository.reload | |
93 |
|
93 | |||
94 | cs1 = @repository.changesets.find_by_revision('13') |
|
94 | cs1 = @repository.changesets.find_by_revision('13') | |
95 | assert_not_nil cs1 |
|
95 | assert_not_nil cs1 | |
96 | c1 = cs1.changes.sort_by(&:path) |
|
96 | c1 = cs1.changes.sort_by(&:path) | |
97 | assert_equal 2, c1.size |
|
97 | assert_equal 2, c1.size | |
98 |
|
98 | |||
99 | assert_equal 'A', c1[0].action |
|
99 | assert_equal 'A', c1[0].action | |
100 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path |
|
100 | 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 |
|
101 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path | |
102 |
|
102 | |||
103 | assert_equal 'A', c1[1].action |
|
103 | assert_equal 'A', c1[1].action | |
104 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path |
|
104 | 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 |
|
105 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path | |
106 |
|
106 | |||
107 | cs2 = @repository.changesets.find_by_revision('15') |
|
107 | cs2 = @repository.changesets.find_by_revision('15') | |
108 | c2 = cs2.changes |
|
108 | c2 = cs2.changes | |
109 | assert_equal 1, c2.size |
|
109 | assert_equal 1, c2.size | |
110 |
|
110 | |||
111 | assert_equal 'A', c2[0].action |
|
111 | assert_equal 'A', c2[0].action | |
112 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path |
|
112 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path | |
113 | assert_equal '/README', c2[0].from_path |
|
113 | assert_equal '/README', c2[0].from_path | |
114 | end |
|
114 | end | |
115 |
|
115 | |||
116 | def test_find_changeset_by_name |
|
116 | def test_find_changeset_by_name | |
117 | @repository.fetch_changesets |
|
117 | @repository.fetch_changesets | |
118 | @repository.reload |
|
118 | @repository.reload | |
119 | %w|2 400bb8672109 400|.each do |r| |
|
119 | %w|2 400bb8672109 400|.each do |r| | |
120 | assert_equal '2', @repository.find_changeset_by_name(r).revision |
|
120 | assert_equal '2', @repository.find_changeset_by_name(r).revision | |
121 | end |
|
121 | end | |
122 | end |
|
122 | end | |
123 |
|
123 | |||
124 | def test_find_changeset_by_invalid_name |
|
124 | def test_find_changeset_by_invalid_name | |
125 | @repository.fetch_changesets |
|
125 | @repository.fetch_changesets | |
126 | @repository.reload |
|
126 | @repository.reload | |
127 | assert_nil @repository.find_changeset_by_name('100000') |
|
127 | assert_nil @repository.find_changeset_by_name('100000') | |
128 | end |
|
128 | end | |
129 |
|
129 | |||
130 | def test_identifier |
|
130 | def test_identifier | |
131 | @repository.fetch_changesets |
|
131 | @repository.fetch_changesets | |
132 | @repository.reload |
|
132 | @repository.reload | |
133 | c = @repository.changesets.find_by_revision('2') |
|
133 | c = @repository.changesets.find_by_revision('2') | |
134 | assert_equal c.scmid, c.identifier |
|
134 | assert_equal c.scmid, c.identifier | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | def test_format_identifier |
|
137 | def test_format_identifier | |
138 | @repository.fetch_changesets |
|
138 | @repository.fetch_changesets | |
139 | @repository.reload |
|
139 | @repository.reload | |
140 | c = @repository.changesets.find_by_revision('2') |
|
140 | c = @repository.changesets.find_by_revision('2') | |
141 | assert_equal '2:400bb8672109', c.format_identifier |
|
141 | assert_equal '2:400bb8672109', c.format_identifier | |
142 | end |
|
142 | end | |
143 |
|
143 | |||
144 | def test_find_changeset_by_empty_name |
|
144 | def test_find_changeset_by_empty_name | |
145 | @repository.fetch_changesets |
|
145 | @repository.fetch_changesets | |
146 | @repository.reload |
|
146 | @repository.reload | |
147 | ['', ' ', nil].each do |r| |
|
147 | ['', ' ', nil].each do |r| | |
148 | assert_nil @repository.find_changeset_by_name(r) |
|
148 | assert_nil @repository.find_changeset_by_name(r) | |
149 | end |
|
149 | end | |
150 | end |
|
150 | end | |
151 |
|
151 | |||
152 | def test_activities |
|
152 | def test_activities | |
153 | c = Changeset.new(:repository => @repository, |
|
153 | c = Changeset.new(:repository => @repository, | |
154 | :committed_on => Time.now, |
|
154 | :committed_on => Time.now, | |
155 | :revision => '123', |
|
155 | :revision => '123', | |
156 | :scmid => 'abc400bb8672', |
|
156 | :scmid => 'abc400bb8672', | |
157 | :comments => 'test') |
|
157 | :comments => 'test') | |
158 | assert c.event_title.include?('123:abc400bb8672:') |
|
158 | assert c.event_title.include?('123:abc400bb8672:') | |
159 | assert_equal 'abc400bb8672', c.event_url[:rev] |
|
159 | assert_equal 'abc400bb8672', c.event_url[:rev] | |
160 | end |
|
160 | end | |
|
161 | ||||
|
162 | def test_latest_changesets_with_limit | |||
|
163 | @repository.fetch_changesets | |||
|
164 | @repository.reload | |||
|
165 | changesets = @repository.latest_changesets('', nil, 2) | |||
|
166 | assert_equal @repository.latest_changesets('', nil)[0, 2], changesets | |||
|
167 | end | |||
|
168 | ||||
|
169 | def test_latest_changesets_with_filepath | |||
|
170 | @repository.fetch_changesets | |||
|
171 | @repository.reload | |||
|
172 | changesets = @repository.latest_changesets('README', nil) | |||
|
173 | assert_equal %w|8 6 1 0|, changesets.collect(&:revision) | |||
|
174 | end | |||
|
175 | ||||
|
176 | def test_latest_changesets_with_dirpath | |||
|
177 | @repository.fetch_changesets | |||
|
178 | @repository.reload | |||
|
179 | changesets = @repository.latest_changesets('images', nil) | |||
|
180 | assert_equal %w|1 0|, changesets.collect(&:revision) | |||
|
181 | end | |||
161 | else |
|
182 | else | |
162 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
183 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
163 | def test_fake; assert true end |
|
184 | def test_fake; assert true end | |
164 | end |
|
185 | end | |
165 | end |
|
186 | end |
General Comments 0
You need to be logged in to leave comments.
Login now