##// END OF EJS Templates
Merged r4636 from trunk....
Toshi MARUYAMA -
r4522:2fcd4e527103
parent child
Show More
@@ -1,103 +1,128
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 assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH)
28 assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH)
29 end
29 end
30
30
31 if File.directory?(REPOSITORY_PATH)
31 if File.directory?(REPOSITORY_PATH)
32 def test_fetch_changesets_from_scratch
32 def test_fetch_changesets_from_scratch
33 @repository.fetch_changesets
33 @repository.fetch_changesets
34 @repository.reload
34 @repository.reload
35
35
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.", @repository.changesets.find_by_revision('0').comments
38 assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments
39 end
39 end
40
40
41 def test_fetch_changesets_incremental
41 def test_fetch_changesets_incremental
42 @repository.fetch_changesets
42 @repository.fetch_changesets
43 # Remove changesets with revision > 2
43 # Remove changesets with revision > 2
44 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
44 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
45 @repository.reload
45 @repository.reload
46 assert_equal 3, @repository.changesets.count
46 assert_equal 3, @repository.changesets.count
47
47
48 @repository.fetch_changesets
48 @repository.fetch_changesets
49 assert_equal 17, @repository.changesets.count
49 assert_equal 17, @repository.changesets.count
50 end
50 end
51
51
52 def test_entries
52 def test_entries
53 assert_equal 2, @repository.entries("sources", 2).size
53 assert_equal 2, @repository.entries("sources", 2).size
54 assert_equal 1, @repository.entries("sources", 3).size
54 assert_equal 1, @repository.entries("sources", 3).size
55 end
55 end
56
56
57 def test_locate_on_outdated_repository
57 def test_locate_on_outdated_repository
58 assert_equal 1, @repository.entries("images", 0).size
58 assert_equal 1, @repository.entries("images", 0).size
59 assert_equal 2, @repository.entries("images").size
59 assert_equal 2, @repository.entries("images").size
60 assert_equal 2, @repository.entries("images", 2).size
60 assert_equal 2, @repository.entries("images", 2).size
61 end
61 end
62
62
63 def test_isodatesec
63 def test_isodatesec
64 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
64 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
65 if @repository.scm.class.client_version_above?([1, 0])
65 if @repository.scm.class.client_version_above?([1, 0])
66 @repository.fetch_changesets
66 @repository.fetch_changesets
67 @repository.reload
67 @repository.reload
68 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
68 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
69 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
69 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
70 end
70 end
71 end
71 end
72
72
73 def test_changeset_order_by_revision
73 def test_changeset_order_by_revision
74 @repository.fetch_changesets
74 @repository.fetch_changesets
75 @repository.reload
75 @repository.reload
76
76
77 c0 = @repository.latest_changeset
77 c0 = @repository.latest_changeset
78 c1 = @repository.changesets.find_by_revision('0')
78 c1 = @repository.changesets.find_by_revision('0')
79 # sorted by revision (id), not by date
79 # sorted by revision (id), not by date
80 assert c0.revision.to_i > c1.revision.to_i
80 assert c0.revision.to_i > c1.revision.to_i
81 assert c0.committed_on < c1.committed_on
81 assert c0.committed_on < c1.committed_on
82 end
82 end
83
83
84 def test_latest_changesets
84 def test_latest_changesets
85 @repository.fetch_changesets
85 @repository.fetch_changesets
86 @repository.reload
86 @repository.reload
87
87
88 # with_limit
88 # with_limit
89 changesets = @repository.latest_changesets('', nil, 2)
89 changesets = @repository.latest_changesets('', nil, 2)
90 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
90 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
91
91
92 # with_filepath
92 # with_filepath
93 changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil)
93 changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil)
94 assert_equal %w|11 10 9|, changesets.collect(&:revision)
94 assert_equal %w|11 10 9|, changesets.collect(&:revision)
95
95
96 changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil)
96 changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil)
97 assert_equal %w|12 9|, changesets.collect(&:revision)
97 assert_equal %w|12 9|, changesets.collect(&:revision)
98 end
98 end
99
100 def test_copied_files
101 @repository.fetch_changesets
102 @repository.reload
103
104 cs1 = @repository.changesets.find_by_revision('13')
105 c1 = cs1.changes
106 assert_equal 2, c1.size
107
108 assert_equal 'A', c1[0].action
109 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
110 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
111
112 assert_equal 'A', c1[1].action
113 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
114 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
115
116 cs2 = @repository.changesets.find_by_revision('15')
117 c2 = cs2.changes
118 assert_equal 1, c2.size
119
120 assert_equal 'A', c2[0].action
121 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
122 assert_equal '/README', c2[0].from_path
123 end
99 else
124 else
100 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
125 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
101 def test_fake; assert true end
126 def test_fake; assert true end
102 end
127 end
103 end
128 end
General Comments 0
You need to be logged in to leave comments. Login now