##// END OF EJS Templates
scm: mercurial: fix assert_equal parameter order at app unit test_find_changeset_by_name()....
Toshi MARUYAMA -
r4535:7484096cdcaf
parent child
Show More
@@ -1,146 +1,146
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.",
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_entries
53 def test_entries
54 assert_equal 2, @repository.entries("sources", 2).size
54 assert_equal 2, @repository.entries("sources", 2).size
55 assert_equal 2, @repository.entries("sources", '400bb8672109').size
55 assert_equal 2, @repository.entries("sources", '400bb8672109').size
56 assert_equal 1, @repository.entries("sources", 3).size
56 assert_equal 1, @repository.entries("sources", 3).size
57 assert_equal 1, @repository.entries("sources", 'b3a615152df8').size
57 assert_equal 1, @repository.entries("sources", 'b3a615152df8').size
58 end
58 end
59
59
60 def test_locate_on_outdated_repository
60 def test_locate_on_outdated_repository
61 assert_equal 1, @repository.entries("images", 0).size
61 assert_equal 1, @repository.entries("images", 0).size
62 assert_equal 2, @repository.entries("images").size
62 assert_equal 2, @repository.entries("images").size
63 assert_equal 2, @repository.entries("images", 2).size
63 assert_equal 2, @repository.entries("images", 2).size
64 end
64 end
65
65
66 def test_isodatesec
66 def test_isodatesec
67 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
67 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
68 if @repository.scm.class.client_version_above?([1, 0])
68 if @repository.scm.class.client_version_above?([1, 0])
69 @repository.fetch_changesets
69 @repository.fetch_changesets
70 @repository.reload
70 @repository.reload
71 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
71 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
72 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
72 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
73 end
73 end
74 end
74 end
75
75
76 def test_changeset_order_by_revision
76 def test_changeset_order_by_revision
77 @repository.fetch_changesets
77 @repository.fetch_changesets
78 @repository.reload
78 @repository.reload
79
79
80 c0 = @repository.latest_changeset
80 c0 = @repository.latest_changeset
81 c1 = @repository.changesets.find_by_revision('0')
81 c1 = @repository.changesets.find_by_revision('0')
82 # sorted by revision (id), not by date
82 # sorted by revision (id), not by date
83 assert c0.revision.to_i > c1.revision.to_i
83 assert c0.revision.to_i > c1.revision.to_i
84 assert c0.committed_on < c1.committed_on
84 assert c0.committed_on < c1.committed_on
85 end
85 end
86
86
87 def test_latest_changesets
87 def test_latest_changesets
88 @repository.fetch_changesets
88 @repository.fetch_changesets
89 @repository.reload
89 @repository.reload
90
90
91 # with_limit
91 # with_limit
92 changesets = @repository.latest_changesets('', nil, 2)
92 changesets = @repository.latest_changesets('', nil, 2)
93 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
93 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
94
94
95 # with_filepath
95 # with_filepath
96 changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil)
96 changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil)
97 assert_equal %w|11 10 9|, changesets.collect(&:revision)
97 assert_equal %w|11 10 9|, changesets.collect(&:revision)
98
98
99 changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil)
99 changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil)
100 assert_equal %w|12 9|, changesets.collect(&:revision)
100 assert_equal %w|12 9|, changesets.collect(&:revision)
101 end
101 end
102
102
103 def test_copied_files
103 def test_copied_files
104 @repository.fetch_changesets
104 @repository.fetch_changesets
105 @repository.reload
105 @repository.reload
106
106
107 cs1 = @repository.changesets.find_by_revision('13')
107 cs1 = @repository.changesets.find_by_revision('13')
108 assert_not_nil cs1
108 assert_not_nil cs1
109 c1 = cs1.changes
109 c1 = cs1.changes
110 assert_equal 2, c1.size
110 assert_equal 2, c1.size
111
111
112 assert_equal 'A', c1[0].action
112 assert_equal 'A', c1[0].action
113 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
113 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
114 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
114 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
115
115
116 assert_equal 'A', c1[1].action
116 assert_equal 'A', c1[1].action
117 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
117 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
118 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
118 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
119
119
120 cs2 = @repository.changesets.find_by_revision('15')
120 cs2 = @repository.changesets.find_by_revision('15')
121 c2 = cs2.changes
121 c2 = cs2.changes
122 assert_equal 1, c2.size
122 assert_equal 1, c2.size
123
123
124 assert_equal 'A', c2[0].action
124 assert_equal 'A', c2[0].action
125 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
125 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
126 assert_equal '/README', c2[0].from_path
126 assert_equal '/README', c2[0].from_path
127 end
127 end
128
128
129 def test_find_changeset_by_name
129 def test_find_changeset_by_name
130 @repository.fetch_changesets
130 @repository.fetch_changesets
131 @repository.reload
131 @repository.reload
132 %w|2 400bb8672109 400|.each do |r|
132 %w|2 400bb8672109 400|.each do |r|
133 assert_equal @repository.find_changeset_by_name(r).revision, '2'
133 assert_equal '2', @repository.find_changeset_by_name(r).revision
134 end
134 end
135 end
135 end
136
136
137 def test_find_changeset_by_invalid_name
137 def test_find_changeset_by_invalid_name
138 @repository.fetch_changesets
138 @repository.fetch_changesets
139 @repository.reload
139 @repository.reload
140 assert_nil @repository.find_changeset_by_name('100000')
140 assert_nil @repository.find_changeset_by_name('100000')
141 end
141 end
142 else
142 else
143 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
143 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
144 def test_fake; assert true end
144 def test_fake; assert true end
145 end
145 end
146 end
146 end
General Comments 0
You need to be logged in to leave comments. Login now