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