##// END OF EJS Templates
Merged r4632 from trunk....
Toshi MARUYAMA -
r4518:6ee4c0bac76e
parent child
Show More
@@ -1,73 +1,73
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 TEMPLATES_DIR = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATES_DIR
7 TEMPLATES_DIR = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATES_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 end
16 end
17
17
18 def test_hgversion
18 def test_hgversion
19 to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5],
19 to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5],
20 "Mercurial Distributed SCM (1.0)\n" => [1,0],
20 "Mercurial Distributed SCM (1.0)\n" => [1,0],
21 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
21 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
22 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
22 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
23 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
23 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
24 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
24 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
25 "(1.6)\n(1.7)\n(1.8)" => [1,6],
25 "(1.6)\n(1.7)\n(1.8)" => [1,6],
26 "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]}
26 "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]}
27
27
28 to_test.each do |s, v|
28 to_test.each do |s, v|
29 test_hgversion_for(s, v)
29 test_hgversion_for(s, v)
30 end
30 end
31 end
31 end
32
32
33 def test_template_path
33 def test_template_path
34 to_test = { [0,9,5] => "0.9.5",
34 to_test = { [0,9,5] => "0.9.5",
35 [1,0] => "1.0",
35 [1,0] => "1.0",
36 [] => "1.0",
36 [] => "1.0",
37 [1,0,1] => "1.0",
37 [1,0,1] => "1.0",
38 [1,7] => "1.0",
38 [1,7] => "1.0",
39 [1,7,1] => "1.0"}
39 [1,7,1] => "1.0" }
40 to_test.each do |v, template|
40 to_test.each do |v, template|
41 test_template_path_for(v, template)
41 test_template_path_for(v, template)
42 end
42 end
43 end
43 end
44
44
45 def test_cat
45 def test_cat
46 assert @adapter.cat("sources/welcome_controller.rb", 2)
46 assert @adapter.cat("sources/welcome_controller.rb", 2)
47 assert_nil @adapter.cat("sources/welcome_controller.rb")
47 assert_nil @adapter.cat("sources/welcome_controller.rb")
48 end
48 end
49
49
50 private
50 private
51
51
52 def test_hgversion_for(hgversion, version)
52 def test_hgversion_for(hgversion, version)
53 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
53 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
54 assert_equal version, @adapter.class.hgversion
54 assert_equal version, @adapter.class.hgversion
55 end
55 end
56
56
57 def test_template_path_for(version, template)
57 def test_template_path_for(version, template)
58 assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
58 assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
59 @adapter.class.template_path_for(version)
59 @adapter.class.template_path_for(version)
60 assert File.exist?(@adapter.class.template_path_for(version))
60 assert File.exist?(@adapter.class.template_path_for(version))
61 end
61 end
62 else
62 else
63 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
63 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
64 def test_fake; assert true end
64 def test_fake; assert true end
65 end
65 end
66 end
66 end
67
67
68 rescue LoadError
68 rescue LoadError
69 class MercurialMochaFake < ActiveSupport::TestCase
69 class MercurialMochaFake < ActiveSupport::TestCase
70 def test_fake; assert(false, "Requires mocha to run those tests") end
70 def test_fake; assert(false, "Requires mocha to run those tests") end
71 end
71 end
72 end
72 end
73
73
General Comments 0
You need to be logged in to leave comments. Login now