##// END OF EJS Templates
scm: git: prepare version string unit lib test and git log encoding (#3396)....
Toshi MARUYAMA -
r4685:ddaf89759666
parent child
Show More
@@ -1,71 +1,92
1 # encoding: utf-8
1 # encoding: utf-8
2
2
3 # This file includes UTF-8 "Felix Schäfer".
4 # We need to consider Ruby 1.9 compatibity.
5
3 require File.expand_path('../../../../../../test_helper', __FILE__)
6 require File.expand_path('../../../../../../test_helper', __FILE__)
7 begin
8 require 'mocha'
4
9
5 class GitAdapterTest < ActiveSupport::TestCase
10 class GitAdapterTest < ActiveSupport::TestCase
6 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
11 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
7
12
8 if File.directory?(REPOSITORY_PATH)
13 if File.directory?(REPOSITORY_PATH)
9 def setup
14 def setup
10 @adapter = Redmine::Scm::Adapters::GitAdapter.new(REPOSITORY_PATH)
15 @adapter = Redmine::Scm::Adapters::GitAdapter.new(REPOSITORY_PATH)
11 end
16 end
12
17
13 def test_branches
18 def test_branches
14 assert_equal @adapter.branches, ['master', 'test_branch']
19 assert_equal @adapter.branches, ['master', 'test_branch']
15 end
20 end
16
21
17 def test_getting_all_revisions
22 def test_getting_all_revisions
18 assert_equal 15, @adapter.revisions('',nil,nil,:all => true).length
23 assert_equal 15, @adapter.revisions('',nil,nil,:all => true).length
19 end
24 end
20
25
21 def test_getting_certain_revisions
26 def test_getting_certain_revisions
22 assert_equal 1, @adapter.revisions('','899a15d^','899a15d').length
27 assert_equal 1, @adapter.revisions('','899a15d^','899a15d').length
23 end
28 end
24
29
25 def test_getting_revisions_with_spaces_in_filename
30 def test_getting_revisions_with_spaces_in_filename
26 assert_equal 1, @adapter.revisions("filemane with spaces.txt", nil, nil, :all => true).length
31 assert_equal 1, @adapter.revisions("filemane with spaces.txt",
27 end
32 nil, nil, :all => true).length
28
33 end
29 def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
34
30 assert_equal " filename with a leading space.txt ", @adapter.revisions(" filename with a leading space.txt ", nil, nil, :all => true)[0].paths[0][:path]
35 def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
31 end
36 assert_equal " filename with a leading space.txt ",
32
37 @adapter.revisions(" filename with a leading space.txt ",
33 def test_getting_entries_with_leading_and_trailing_spaces_in_filename
38 nil, nil, :all => true)[0].paths[0][:path]
34 assert_equal " filename with a leading space.txt ", @adapter.entries('', '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
39 end
35 end
40
36
41 def test_getting_entries_with_leading_and_trailing_spaces_in_filename
37 def test_annotate
42 assert_equal " filename with a leading space.txt ",
38 annotate = @adapter.annotate('sources/watchers_controller.rb')
43 @adapter.entries('',
39 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
44 '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
40 assert_equal 41, annotate.lines.size
45 end
41 assert_equal "# This program is free software; you can redistribute it and/or", annotate.lines[4].strip
46
42 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", annotate.revisions[4].identifier
47 def test_annotate
43 assert_equal "jsmith", annotate.revisions[4].author
48 annotate = @adapter.annotate('sources/watchers_controller.rb')
44 end
49 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
45
50 assert_equal 41, annotate.lines.size
46 def test_annotate_moved_file
51 assert_equal "# This program is free software; you can redistribute it and/or", annotate.lines[4].strip
47 annotate = @adapter.annotate('renamed_test.txt')
52 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
48 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
53 annotate.revisions[4].identifier
49 assert_equal 2, annotate.lines.size
54 assert_equal "jsmith", annotate.revisions[4].author
50 end
55 end
51
56
52 def test_last_rev
57 def test_annotate_moved_file
53 last_rev = @adapter.lastrev("README", "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
58 annotate = @adapter.annotate('renamed_test.txt')
54 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
59 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
55 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
60 assert_equal 2, annotate.lines.size
56 assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
61 end
57 assert_equal "2009-06-24 05:27:38".to_time, last_rev.time
62
58 end
63 def test_last_rev
59
64 last_rev = @adapter.lastrev("README",
60 def test_last_rev_with_spaces_in_filename
65 "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
61 last_rev = @adapter.lastrev("filemane with spaces.txt", "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
66 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
62 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
67 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
63 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
68 assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
64 assert_equal "Felix Schäfer <felix@fachschaften.org>", last_rev.author
69 assert_equal "2009-06-24 05:27:38".to_time, last_rev.time
65 assert_equal "2010-09-18 19:59:46".to_time, last_rev.time
70 end
71
72 def test_last_rev_with_spaces_in_filename
73 last_rev = @adapter.lastrev("filemane with spaces.txt",
74 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
75 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
76 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
77 assert_equal "Felix Schäfer <felix@fachschaften.org>",
78 last_rev.author
79 assert_equal "2010-09-18 19:59:46".to_time, last_rev.time
80 end
81 else
82 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
83 def test_fake; assert true end
66 end
84 end
67 else
85 end
68 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
86
69 def test_fake; assert true end
87 rescue LoadError
88 class GitMochaFake < ActiveSupport::TestCase
89 def test_fake; assert(false, "Requires mocha to run those tests") end
70 end
90 end
71 end
91 end
92
General Comments 0
You need to be logged in to leave comments. Login now