##// END OF EJS Templates
Adds a test for CvsAdapter#root_url_path (#14422)....
Jean-Philippe Lang -
r11787:01f259be0d56
parent child
Show More
@@ -1,99 +1,104
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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 begin
19 begin
20 require 'mocha/setup'
20 require 'mocha/setup'
21
21
22 class CvsAdapterTest < ActiveSupport::TestCase
22 class CvsAdapterTest < ActiveSupport::TestCase
23 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
23 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
24 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
24 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
25 MODULE_NAME = 'test'
25 MODULE_NAME = 'test'
26
26
27 if File.directory?(REPOSITORY_PATH)
27 if File.directory?(REPOSITORY_PATH)
28 def setup
28 def setup
29 @adapter = Redmine::Scm::Adapters::CvsAdapter.new(MODULE_NAME, REPOSITORY_PATH)
29 @adapter = Redmine::Scm::Adapters::CvsAdapter.new(MODULE_NAME, REPOSITORY_PATH)
30 end
30 end
31
31
32 def test_scm_version
32 def test_scm_version
33 to_test = { "\nConcurrent Versions System (CVS) 1.12.13 (client/server)\n" => [1,12,13],
33 to_test = { "\nConcurrent Versions System (CVS) 1.12.13 (client/server)\n" => [1,12,13],
34 "\r\n1.12.12\r\n1.12.11" => [1,12,12],
34 "\r\n1.12.12\r\n1.12.11" => [1,12,12],
35 "1.12.11\r\n1.12.10\r\n" => [1,12,11]}
35 "1.12.11\r\n1.12.10\r\n" => [1,12,11]}
36 to_test.each do |s, v|
36 to_test.each do |s, v|
37 test_scm_version_for(s, v)
37 test_scm_version_for(s, v)
38 end
38 end
39 end
39 end
40
40
41 def test_revisions_all
41 def test_revisions_all
42 cnt = 0
42 cnt = 0
43 @adapter.revisions('', nil, nil, :log_encoding => 'UTF-8') do |revision|
43 @adapter.revisions('', nil, nil, :log_encoding => 'UTF-8') do |revision|
44 cnt += 1
44 cnt += 1
45 end
45 end
46 assert_equal 16, cnt
46 assert_equal 16, cnt
47 end
47 end
48
48
49 def test_revisions_from_rev3
49 def test_revisions_from_rev3
50 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
50 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
51 cnt = 0
51 cnt = 0
52 @adapter.revisions('', rev3_committed_on, nil, :log_encoding => 'UTF-8') do |revision|
52 @adapter.revisions('', rev3_committed_on, nil, :log_encoding => 'UTF-8') do |revision|
53 cnt += 1
53 cnt += 1
54 end
54 end
55 assert_equal 4, cnt
55 assert_equal 4, cnt
56 end
56 end
57
57
58 def test_entries_rev3
58 def test_entries_rev3
59 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
59 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
60 entries = @adapter.entries('sources', rev3_committed_on)
60 entries = @adapter.entries('sources', rev3_committed_on)
61 assert_equal 2, entries.size
61 assert_equal 2, entries.size
62 assert_equal entries[0].name, "watchers_controller.rb"
62 assert_equal entries[0].name, "watchers_controller.rb"
63 assert_equal entries[0].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
63 assert_equal entries[0].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
64 end
64 end
65
65
66 def test_path_encoding_default_utf8
66 def test_path_encoding_default_utf8
67 adpt1 = Redmine::Scm::Adapters::CvsAdapter.new(
67 adpt1 = Redmine::Scm::Adapters::CvsAdapter.new(
68 MODULE_NAME,
68 MODULE_NAME,
69 REPOSITORY_PATH
69 REPOSITORY_PATH
70 )
70 )
71 assert_equal "UTF-8", adpt1.path_encoding
71 assert_equal "UTF-8", adpt1.path_encoding
72 adpt2 = Redmine::Scm::Adapters::CvsAdapter.new(
72 adpt2 = Redmine::Scm::Adapters::CvsAdapter.new(
73 MODULE_NAME,
73 MODULE_NAME,
74 REPOSITORY_PATH,
74 REPOSITORY_PATH,
75 nil,
75 nil,
76 nil,
76 nil,
77 ""
77 ""
78 )
78 )
79 assert_equal "UTF-8", adpt2.path_encoding
79 assert_equal "UTF-8", adpt2.path_encoding
80 end
80 end
81
81
82 def test_root_url_path
83 adapter = Redmine::Scm::Adapters::CvsAdapter.new('foo', ':pserver:cvs_user:cvs_password@123.456.789.123:9876/repo')
84 assert_equal '/repo', adapter.send(:root_url_path)
85 end
86
82 private
87 private
83
88
84 def test_scm_version_for(scm_command_version, version)
89 def test_scm_version_for(scm_command_version, version)
85 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
90 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
86 assert_equal version, @adapter.class.scm_command_version
91 assert_equal version, @adapter.class.scm_command_version
87 end
92 end
88 else
93 else
89 puts "Cvs test repository NOT FOUND. Skipping unit tests !!!"
94 puts "Cvs test repository NOT FOUND. Skipping unit tests !!!"
90 def test_fake; assert true end
95 def test_fake; assert true end
91 end
96 end
92 end
97 end
93
98
94 rescue LoadError
99 rescue LoadError
95 class CvsMochaFake < ActiveSupport::TestCase
100 class CvsMochaFake < ActiveSupport::TestCase
96 def test_fake; assert(false, "Requires mocha to run those tests") end
101 def test_fake; assert(false, "Requires mocha to run those tests") end
97 end
102 end
98 end
103 end
99
104
General Comments 0
You need to be logged in to leave comments. Login now