@@ -9,49 +9,62 begin | |||
|
9 | 9 | TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION |
|
10 | 10 | |
|
11 | 11 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' |
|
12 | ||
|
13 | def test_hgversion | |
|
14 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], | |
|
15 | "Mercurial Distributed SCM (1.0)\n" => [1,0], | |
|
16 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, | |
|
17 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], | |
|
18 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, | |
|
19 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], | |
|
20 | "(1.6)\n(1.7)\n(1.8)" => [1,6], | |
|
21 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} | |
|
22 | ||
|
23 | to_test.each do |s, v| | |
|
24 | test_hgversion_for(s, v) | |
|
12 | ||
|
13 | if File.directory?(REPOSITORY_PATH) | |
|
14 | def setup | |
|
15 | @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH) | |
|
25 | 16 | end |
|
26 | end | |
|
27 | ||
|
28 | def test_template_path | |
|
29 | to_test = { [0,9,5] => "0.9.5", | |
|
30 | [1,0] => "1.0", | |
|
31 | [] => "1.0", | |
|
32 | [1,0,1] => "1.0", | |
|
33 | [1,7] => "1.0", | |
|
34 | [1,7,1] => "1.0"} | |
|
35 | to_test.each do |v, template| | |
|
36 | test_template_path_for(v, template) | |
|
17 | ||
|
18 | def test_hgversion | |
|
19 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], | |
|
20 | "Mercurial Distributed SCM (1.0)\n" => [1,0], | |
|
21 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, | |
|
22 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], | |
|
23 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, | |
|
24 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], | |
|
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]} | |
|
27 | ||
|
28 | to_test.each do |s, v| | |
|
29 | test_hgversion_for(s, v) | |
|
30 | end | |
|
37 | 31 | end |
|
38 | end | |
|
39 | ||
|
40 | private | |
|
41 | ||
|
42 | def test_hgversion_for(hgversion, version) | |
|
43 | Redmine::Scm::Adapters::MercurialAdapter.expects(:hgversion_from_command_line).returns(hgversion) | |
|
44 | adapter = Redmine::Scm::Adapters::MercurialAdapter | |
|
45 | assert_equal version, adapter.hgversion | |
|
46 | end | |
|
47 | ||
|
48 | def test_template_path_for(version, template) | |
|
49 | adapter = Redmine::Scm::Adapters::MercurialAdapter | |
|
50 | assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", adapter.template_path_for(version) | |
|
51 | assert File.exist?(adapter.template_path_for(version)) | |
|
32 | ||
|
33 | def test_template_path | |
|
34 | to_test = { [0,9,5] => "0.9.5", | |
|
35 | [1,0] => "1.0", | |
|
36 | [] => "1.0", | |
|
37 | [1,0,1] => "1.0", | |
|
38 | [1,7] => "1.0", | |
|
39 | [1,7,1] => "1.0"} | |
|
40 | to_test.each do |v, template| | |
|
41 | test_template_path_for(v, template) | |
|
42 | end | |
|
43 | end | |
|
44 | ||
|
45 | def test_cat | |
|
46 | assert @adapter.cat("sources/welcome_controller.rb", 2) | |
|
47 | assert_nil @adapter.cat("sources/welcome_controller.rb") | |
|
48 | end | |
|
49 | ||
|
50 | private | |
|
51 | ||
|
52 | def test_hgversion_for(hgversion, version) | |
|
53 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) | |
|
54 | assert_equal version, @adapter.class.hgversion | |
|
55 | end | |
|
56 | ||
|
57 | def test_template_path_for(version, template) | |
|
58 | assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", | |
|
59 | @adapter.class.template_path_for(version) | |
|
60 | assert File.exist?(@adapter.class.template_path_for(version)) | |
|
61 | end | |
|
62 | else | |
|
63 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
|
64 | def test_fake; assert true end | |
|
52 | 65 | end |
|
53 | 66 | end |
|
54 | ||
|
67 | ||
|
55 | 68 | rescue LoadError |
|
56 | 69 | class MercurialMochaFake < ActiveSupport::TestCase |
|
57 | 70 | def test_fake; assert(false, "Requires mocha to run those tests") end |
@@ -55,18 +55,11 class RepositoryMercurialTest < ActiveSupport::TestCase | |||
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | def test_locate_on_outdated_repository |
|
58 | # Change the working dir state | |
|
59 | %x{hg -R #{REPOSITORY_PATH} up -r 0} | |
|
60 | 58 | assert_equal 1, @repository.entries("images", 0).size |
|
61 | 59 | assert_equal 2, @repository.entries("images").size |
|
62 | 60 | assert_equal 2, @repository.entries("images", 2).size |
|
63 | 61 | end |
|
64 | 62 | |
|
65 | def test_cat | |
|
66 | assert @repository.scm.cat("sources/welcome_controller.rb", 2) | |
|
67 | assert_nil @repository.scm.cat("sources/welcome_controller.rb") | |
|
68 | end | |
|
69 | ||
|
70 | 63 | def test_isodatesec |
|
71 | 64 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher |
|
72 | 65 | if @repository.scm.class.client_version_above?([1, 0]) |
General Comments 0
You need to be logged in to leave comments.
Login now