##// END OF EJS Templates
scm: mercurial: move entries unit test from app to lib....
Toshi MARUYAMA -
r4743:a3a9661da6fc
parent child
Show More
@@ -1,193 +1,203
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 = true
16 @diff_c_support = true
17 end
17 end
18
18
19 def test_hgversion
19 def test_hgversion
20 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],
21 "Mercurial Distributed SCM (1.0)\n" => [1,0],
21 "Mercurial Distributed SCM (1.0)\n" => [1,0],
22 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
22 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
23 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
23 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
24 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
24 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
25 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
25 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
26 "(1.6)\n(1.7)\n(1.8)" => [1,6],
26 "(1.6)\n(1.7)\n(1.8)" => [1,6],
27 "(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]}
28
28
29 to_test.each do |s, v|
29 to_test.each do |s, v|
30 test_hgversion_for(s, v)
30 test_hgversion_for(s, v)
31 end
31 end
32 end
32 end
33
33
34 def test_template_path
34 def test_template_path
35 to_test = { [0,9,5] => "0.9.5",
35 to_test = { [0,9,5] => "0.9.5",
36 [1,0] => "1.0",
36 [1,0] => "1.0",
37 [] => "1.0",
37 [] => "1.0",
38 [1,0,1] => "1.0",
38 [1,0,1] => "1.0",
39 [1,7] => "1.0",
39 [1,7] => "1.0",
40 [1,7,1] => "1.0" }
40 [1,7,1] => "1.0" }
41 to_test.each do |v, template|
41 to_test.each do |v, template|
42 test_template_path_for(v, template)
42 test_template_path_for(v, template)
43 end
43 end
44 end
44 end
45
45
46 def test_info
46 def test_info
47 [REPOSITORY_PATH, REPOSITORY_PATH + "/",
47 [REPOSITORY_PATH, REPOSITORY_PATH + "/",
48 REPOSITORY_PATH + "//"].each do |repo|
48 REPOSITORY_PATH + "//"].each do |repo|
49 adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo)
49 adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo)
50 repo_path = adp.info.root_url.gsub(/\\/, "/")
50 repo_path = adp.info.root_url.gsub(/\\/, "/")
51 assert_equal REPOSITORY_PATH, repo_path
51 assert_equal REPOSITORY_PATH, repo_path
52 assert_equal '16', adp.info.lastrev.revision
52 assert_equal '16', adp.info.lastrev.revision
53 assert_equal '4cddb4e45f52',adp.info.lastrev.scmid
53 assert_equal '4cddb4e45f52',adp.info.lastrev.scmid
54 end
54 end
55 end
55 end
56
56
57 def test_revisions
57 def test_revisions
58 revisions = @adapter.revisions(nil, 2, 4)
58 revisions = @adapter.revisions(nil, 2, 4)
59 assert_equal 3, revisions.size
59 assert_equal 3, revisions.size
60 assert_equal '2', revisions[0].revision
60 assert_equal '2', revisions[0].revision
61 assert_equal '400bb8672109', revisions[0].scmid
61 assert_equal '400bb8672109', revisions[0].scmid
62 assert_equal '4', revisions[2].revision
62 assert_equal '4', revisions[2].revision
63 assert_equal 'def6d2f1254a', revisions[2].scmid
63 assert_equal 'def6d2f1254a', revisions[2].scmid
64
64
65 revisions = @adapter.revisions(nil, 2, 4, {:limit => 2})
65 revisions = @adapter.revisions(nil, 2, 4, {:limit => 2})
66 assert_equal 2, revisions.size
66 assert_equal 2, revisions.size
67 assert_equal '2', revisions[0].revision
67 assert_equal '2', revisions[0].revision
68 assert_equal '400bb8672109', revisions[0].scmid
68 assert_equal '400bb8672109', revisions[0].scmid
69 end
69 end
70
70
71 def test_diff
71 def test_diff
72 if @adapter.class.client_version_above?([1, 2])
72 if @adapter.class.client_version_above?([1, 2])
73 assert_nil @adapter.diff(nil, '100000')
73 assert_nil @adapter.diff(nil, '100000')
74 end
74 end
75 assert_nil @adapter.diff(nil, '100000', '200000')
75 assert_nil @adapter.diff(nil, '100000', '200000')
76 [2, '400bb8672109', '400', 400].each do |r1|
76 [2, '400bb8672109', '400', 400].each do |r1|
77 diff1 = @adapter.diff(nil, r1)
77 diff1 = @adapter.diff(nil, r1)
78 if @diff_c_support
78 if @diff_c_support
79 assert_equal 28, diff1.size
79 assert_equal 28, diff1.size
80 buf = diff1[24].gsub(/\r\n|\r|\n/, "")
80 buf = diff1[24].gsub(/\r\n|\r|\n/, "")
81 assert_equal "+ return true unless klass.respond_to?('watched_by')", buf
81 assert_equal "+ return true unless klass.respond_to?('watched_by')", buf
82 else
82 else
83 assert_equal 0, diff1.size
83 assert_equal 0, diff1.size
84 end
84 end
85 [4, 'def6d2f1254a'].each do |r2|
85 [4, 'def6d2f1254a'].each do |r2|
86 diff2 = @adapter.diff(nil,r1,r2)
86 diff2 = @adapter.diff(nil,r1,r2)
87 assert_equal 49, diff2.size
87 assert_equal 49, diff2.size
88 buf = diff2[41].gsub(/\r\n|\r|\n/, "")
88 buf = diff2[41].gsub(/\r\n|\r|\n/, "")
89 assert_equal "+class WelcomeController < ApplicationController", buf
89 assert_equal "+class WelcomeController < ApplicationController", buf
90 diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2)
90 diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2)
91 assert_equal 20, diff3.size
91 assert_equal 20, diff3.size
92 buf = diff3[12].gsub(/\r\n|\r|\n/, "")
92 buf = diff3[12].gsub(/\r\n|\r|\n/, "")
93 assert_equal "+ @watched.remove_watcher(user)", buf
93 assert_equal "+ @watched.remove_watcher(user)", buf
94 end
94 end
95 end
95 end
96 end
96 end
97
97
98 def test_diff_made_by_revision
98 def test_diff_made_by_revision
99 if @diff_c_support
99 if @diff_c_support
100 [16, '16', '4cddb4e45f52'].each do |r1|
100 [16, '16', '4cddb4e45f52'].each do |r1|
101 diff1 = @adapter.diff(nil, r1)
101 diff1 = @adapter.diff(nil, r1)
102 assert_equal 5, diff1.size
102 assert_equal 5, diff1.size
103 buf = diff1[4].gsub(/\r\n|\r|\n/, "")
103 buf = diff1[4].gsub(/\r\n|\r|\n/, "")
104 assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf
104 assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf
105 end
105 end
106 end
106 end
107 end
107 end
108
108
109 def test_cat
109 def test_cat
110 [2, '400bb8672109', '400', 400].each do |r|
110 [2, '400bb8672109', '400', 400].each do |r|
111 buf = @adapter.cat('sources/welcome_controller.rb', r)
111 buf = @adapter.cat('sources/welcome_controller.rb', r)
112 assert buf
112 assert buf
113 lines = buf.split("\r\n")
113 lines = buf.split("\r\n")
114 assert_equal 25, lines.length
114 assert_equal 25, lines.length
115 assert_equal 'class WelcomeController < ApplicationController', lines[17]
115 assert_equal 'class WelcomeController < ApplicationController', lines[17]
116 end
116 end
117 assert_nil @adapter.cat('sources/welcome_controller.rb')
117 assert_nil @adapter.cat('sources/welcome_controller.rb')
118 end
118 end
119
119
120 def test_annotate
120 def test_annotate
121 assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines
121 assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines
122 [2, '400bb8672109', '400', 400].each do |r|
122 [2, '400bb8672109', '400', 400].each do |r|
123 ann = @adapter.annotate('sources/welcome_controller.rb', r)
123 ann = @adapter.annotate('sources/welcome_controller.rb', r)
124 assert ann
124 assert ann
125 assert_equal '1', ann.revisions[17].revision
125 assert_equal '1', ann.revisions[17].revision
126 assert_equal '9d5b5b004199', ann.revisions[17].identifier
126 assert_equal '9d5b5b004199', ann.revisions[17].identifier
127 assert_equal 'jsmith', ann.revisions[0].author
127 assert_equal 'jsmith', ann.revisions[0].author
128 assert_equal 25, ann.lines.length
128 assert_equal 25, ann.lines.length
129 assert_equal 'class WelcomeController < ApplicationController', ann.lines[17]
129 assert_equal 'class WelcomeController < ApplicationController', ann.lines[17]
130 end
130 end
131 end
131 end
132
132
133 # TODO filesize etc.
133 # TODO filesize etc.
134 def test_entries
134 def test_entries
135 assert_nil @adapter.entries(nil, '100000')
135 assert_nil @adapter.entries(nil, '100000')
136
137 assert_equal 1, @adapter.entries("sources", 3).size
138 assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size
139
136 [2, '400bb8672109', '400', 400].each do |r|
140 [2, '400bb8672109', '400', 400].each do |r|
137 entries1 = @adapter.entries(nil, r)
141 entries1 = @adapter.entries(nil, r)
138 assert entries1
142 assert entries1
139 assert_equal 3, entries1.size
143 assert_equal 3, entries1.size
140 assert_equal 'sources', entries1[1].name
144 assert_equal 'sources', entries1[1].name
141 assert_equal 'sources', entries1[1].path
145 assert_equal 'sources', entries1[1].path
142 assert_equal 'dir', entries1[1].kind
146 assert_equal 'dir', entries1[1].kind
143 assert_equal 'README', entries1[2].name
147 assert_equal 'README', entries1[2].name
144 assert_equal 'README', entries1[2].path
148 assert_equal 'README', entries1[2].path
145 assert_equal 'file', entries1[2].kind
149 assert_equal 'file', entries1[2].kind
146
150
147 entries2 = @adapter.entries('sources', r)
151 entries2 = @adapter.entries('sources', r)
148 assert entries2
152 assert entries2
149 assert_equal 2, entries2.size
153 assert_equal 2, entries2.size
150 assert_equal 'watchers_controller.rb', entries2[0].name
154 assert_equal 'watchers_controller.rb', entries2[0].name
151 assert_equal 'sources/watchers_controller.rb', entries2[0].path
155 assert_equal 'sources/watchers_controller.rb', entries2[0].path
152 assert_equal 'file', entries2[0].kind
156 assert_equal 'file', entries2[0].kind
153 assert_equal 'welcome_controller.rb', entries2[1].name
157 assert_equal 'welcome_controller.rb', entries2[1].name
154 assert_equal 'sources/welcome_controller.rb', entries2[1].path
158 assert_equal 'sources/welcome_controller.rb', entries2[1].path
155 assert_equal 'file', entries2[1].kind
159 assert_equal 'file', entries2[1].kind
156 end
160 end
157 end
161 end
158
162
163 def test_locate_on_outdated_repository
164 assert_equal 1, @adapter.entries("images", 0).size
165 assert_equal 2, @adapter.entries("images").size
166 assert_equal 2, @adapter.entries("images", 2).size
167 end
168
159 def test_access_by_nodeid
169 def test_access_by_nodeid
160 path = 'sources/welcome_controller.rb'
170 path = 'sources/welcome_controller.rb'
161 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
171 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
162 end
172 end
163
173
164 def test_access_by_fuzzy_nodeid
174 def test_access_by_fuzzy_nodeid
165 path = 'sources/welcome_controller.rb'
175 path = 'sources/welcome_controller.rb'
166 # falls back to nodeid
176 # falls back to nodeid
167 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
177 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
168 end
178 end
169
179
170 private
180 private
171
181
172 def test_hgversion_for(hgversion, version)
182 def test_hgversion_for(hgversion, version)
173 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
183 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
174 assert_equal version, @adapter.class.hgversion
184 assert_equal version, @adapter.class.hgversion
175 end
185 end
176
186
177 def test_template_path_for(version, template)
187 def test_template_path_for(version, template)
178 assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
188 assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
179 @adapter.class.template_path_for(version)
189 @adapter.class.template_path_for(version)
180 assert File.exist?(@adapter.class.template_path_for(version))
190 assert File.exist?(@adapter.class.template_path_for(version))
181 end
191 end
182 else
192 else
183 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
193 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
184 def test_fake; assert true end
194 def test_fake; assert true end
185 end
195 end
186 end
196 end
187
197
188 rescue LoadError
198 rescue LoadError
189 class MercurialMochaFake < ActiveSupport::TestCase
199 class MercurialMochaFake < ActiveSupport::TestCase
190 def test_fake; assert(false, "Requires mocha to run those tests") end
200 def test_fake; assert(false, "Requires mocha to run those tests") end
191 end
201 end
192 end
202 end
193
203
@@ -1,178 +1,165
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_entries
54 assert_equal 2, @repository.entries("sources", 2).size
55 assert_equal 2, @repository.entries("sources", '400bb8672109').size
56 assert_equal 1, @repository.entries("sources", 3).size
57 assert_equal 1, @repository.entries("sources", 'b3a615152df8').size
58 end
59
60 def test_locate_on_outdated_repository
61 assert_equal 1, @repository.entries("images", 0).size
62 assert_equal 2, @repository.entries("images").size
63 assert_equal 2, @repository.entries("images", 2).size
64 end
65
66 def test_isodatesec
53 def test_isodatesec
67 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
54 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
68 if @repository.scm.class.client_version_above?([1, 0])
55 if @repository.scm.class.client_version_above?([1, 0])
69 @repository.fetch_changesets
56 @repository.fetch_changesets
70 @repository.reload
57 @repository.reload
71 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
58 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
59 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
73 end
60 end
74 end
61 end
75
62
76 def test_changeset_order_by_revision
63 def test_changeset_order_by_revision
77 @repository.fetch_changesets
64 @repository.fetch_changesets
78 @repository.reload
65 @repository.reload
79
66
80 c0 = @repository.latest_changeset
67 c0 = @repository.latest_changeset
81 c1 = @repository.changesets.find_by_revision('0')
68 c1 = @repository.changesets.find_by_revision('0')
82 # sorted by revision (id), not by date
69 # sorted by revision (id), not by date
83 assert c0.revision.to_i > c1.revision.to_i
70 assert c0.revision.to_i > c1.revision.to_i
84 assert c0.committed_on < c1.committed_on
71 assert c0.committed_on < c1.committed_on
85 end
72 end
86
73
87 def test_latest_changesets
74 def test_latest_changesets
88 @repository.fetch_changesets
75 @repository.fetch_changesets
89 @repository.reload
76 @repository.reload
90
77
91 # with_limit
78 # with_limit
92 changesets = @repository.latest_changesets('', nil, 2)
79 changesets = @repository.latest_changesets('', nil, 2)
93 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
80 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
94
81
95 # with_filepath
82 # with_filepath
96 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)
97 assert_equal %w|11 10 9|, changesets.collect(&:revision)
84 assert_equal %w|11 10 9|, changesets.collect(&:revision)
98
85
99 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)
100 assert_equal %w|12 9|, changesets.collect(&:revision)
87 assert_equal %w|12 9|, changesets.collect(&:revision)
101 end
88 end
102
89
103 def test_copied_files
90 def test_copied_files
104 @repository.fetch_changesets
91 @repository.fetch_changesets
105 @repository.reload
92 @repository.reload
106
93
107 cs1 = @repository.changesets.find_by_revision('13')
94 cs1 = @repository.changesets.find_by_revision('13')
108 assert_not_nil cs1
95 assert_not_nil cs1
109 c1 = cs1.changes.sort_by(&:path)
96 c1 = cs1.changes.sort_by(&:path)
110 assert_equal 2, c1.size
97 assert_equal 2, c1.size
111
98
112 assert_equal 'A', c1[0].action
99 assert_equal 'A', c1[0].action
113 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
100 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
101 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
115
102
116 assert_equal 'A', c1[1].action
103 assert_equal 'A', c1[1].action
117 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
118 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
119
106
120 cs2 = @repository.changesets.find_by_revision('15')
107 cs2 = @repository.changesets.find_by_revision('15')
121 c2 = cs2.changes
108 c2 = cs2.changes
122 assert_equal 1, c2.size
109 assert_equal 1, c2.size
123
110
124 assert_equal 'A', c2[0].action
111 assert_equal 'A', c2[0].action
125 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
112 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
126 assert_equal '/README', c2[0].from_path
113 assert_equal '/README', c2[0].from_path
127 end
114 end
128
115
129 def test_find_changeset_by_name
116 def test_find_changeset_by_name
130 @repository.fetch_changesets
117 @repository.fetch_changesets
131 @repository.reload
118 @repository.reload
132 %w|2 400bb8672109 400|.each do |r|
119 %w|2 400bb8672109 400|.each do |r|
133 assert_equal '2', @repository.find_changeset_by_name(r).revision
120 assert_equal '2', @repository.find_changeset_by_name(r).revision
134 end
121 end
135 end
122 end
136
123
137 def test_find_changeset_by_invalid_name
124 def test_find_changeset_by_invalid_name
138 @repository.fetch_changesets
125 @repository.fetch_changesets
139 @repository.reload
126 @repository.reload
140 assert_nil @repository.find_changeset_by_name('100000')
127 assert_nil @repository.find_changeset_by_name('100000')
141 end
128 end
142
129
143 def test_identifier
130 def test_identifier
144 @repository.fetch_changesets
131 @repository.fetch_changesets
145 @repository.reload
132 @repository.reload
146 c = @repository.changesets.find_by_revision('2')
133 c = @repository.changesets.find_by_revision('2')
147 assert_equal c.scmid, c.identifier
134 assert_equal c.scmid, c.identifier
148 end
135 end
149
136
150 def test_format_identifier
137 def test_format_identifier
151 @repository.fetch_changesets
138 @repository.fetch_changesets
152 @repository.reload
139 @repository.reload
153 c = @repository.changesets.find_by_revision('2')
140 c = @repository.changesets.find_by_revision('2')
154 assert_equal '2:400bb8672109', c.format_identifier
141 assert_equal '2:400bb8672109', c.format_identifier
155 end
142 end
156
143
157 def test_find_changeset_by_empty_name
144 def test_find_changeset_by_empty_name
158 @repository.fetch_changesets
145 @repository.fetch_changesets
159 @repository.reload
146 @repository.reload
160 ['', ' ', nil].each do |r|
147 ['', ' ', nil].each do |r|
161 assert_nil @repository.find_changeset_by_name(r)
148 assert_nil @repository.find_changeset_by_name(r)
162 end
149 end
163 end
150 end
164
151
165 def test_activities
152 def test_activities
166 c = Changeset.new(:repository => @repository,
153 c = Changeset.new(:repository => @repository,
167 :committed_on => Time.now,
154 :committed_on => Time.now,
168 :revision => '123',
155 :revision => '123',
169 :scmid => 'abc400bb8672',
156 :scmid => 'abc400bb8672',
170 :comments => 'test')
157 :comments => 'test')
171 assert c.event_title.include?('123:abc400bb8672:')
158 assert c.event_title.include?('123:abc400bb8672:')
172 assert_equal 'abc400bb8672', c.event_url[:rev]
159 assert_equal 'abc400bb8672', c.event_url[:rev]
173 end
160 end
174 else
161 else
175 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
162 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
176 def test_fake; assert true end
163 def test_fake; assert true end
177 end
164 end
178 end
165 end
General Comments 0
You need to be logged in to leave comments. Login now