##// END OF EJS Templates
scm: git: update test repository for path encoding (#5251)....
Toshi MARUYAMA -
r4906:3a56e1eeab0f
parent child
Show More
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,120 +1,121
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 compatibility.
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 FELIX_UTF8 = "Felix Schäfer"
13 FELIX_UTF8 = "Felix Schäfer"
14 FELIX_HEX = "Felix Sch\xC3\xA4fer"
14 FELIX_HEX = "Felix Sch\xC3\xA4fer"
15
15
16 if File.directory?(REPOSITORY_PATH)
16 if File.directory?(REPOSITORY_PATH)
17 def setup
17 def setup
18 @adapter = Redmine::Scm::Adapters::GitAdapter.new(REPOSITORY_PATH)
18 @adapter = Redmine::Scm::Adapters::GitAdapter.new(REPOSITORY_PATH)
19 end
19 end
20
20
21 def test_scm_version
21 def test_scm_version
22 to_test = { "git version 1.7.3.4\n" => [1,7,3,4],
22 to_test = { "git version 1.7.3.4\n" => [1,7,3,4],
23 "1.6.1\n1.7\n1.8" => [1,6,1],
23 "1.6.1\n1.7\n1.8" => [1,6,1],
24 "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]}
24 "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]}
25 to_test.each do |s, v|
25 to_test.each do |s, v|
26 test_scm_version_for(s, v)
26 test_scm_version_for(s, v)
27 end
27 end
28 end
28 end
29
29
30 def test_branches
30 def test_branches
31 assert_equal @adapter.branches, ['master', 'test-latin-1', 'test_branch']
31 assert_equal ['latin-1-path-encoding', 'master', 'test-latin-1', 'test_branch'],
32 @adapter.branches
32 end
33 end
33
34
34 def test_getting_all_revisions
35 def test_getting_all_revisions
35 assert_equal 16, @adapter.revisions('',nil,nil,:all => true).length
36 assert_equal 21, @adapter.revisions('',nil,nil,:all => true).length
36 end
37 end
37
38
38 def test_getting_certain_revisions
39 def test_getting_certain_revisions
39 assert_equal 1, @adapter.revisions('','899a15d^','899a15d').length
40 assert_equal 1, @adapter.revisions('','899a15d^','899a15d').length
40 end
41 end
41
42
42 def test_getting_revisions_with_spaces_in_filename
43 def test_getting_revisions_with_spaces_in_filename
43 assert_equal 1, @adapter.revisions("filemane with spaces.txt",
44 assert_equal 1, @adapter.revisions("filemane with spaces.txt",
44 nil, nil, :all => true).length
45 nil, nil, :all => true).length
45 end
46 end
46
47
47 def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
48 def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
48 assert_equal " filename with a leading space.txt ",
49 assert_equal " filename with a leading space.txt ",
49 @adapter.revisions(" filename with a leading space.txt ",
50 @adapter.revisions(" filename with a leading space.txt ",
50 nil, nil, :all => true)[0].paths[0][:path]
51 nil, nil, :all => true)[0].paths[0][:path]
51 end
52 end
52
53
53 def test_getting_entries_with_leading_and_trailing_spaces_in_filename
54 def test_getting_entries_with_leading_and_trailing_spaces_in_filename
54 assert_equal " filename with a leading space.txt ",
55 assert_equal " filename with a leading space.txt ",
55 @adapter.entries('',
56 @adapter.entries('',
56 '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
57 '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
57 end
58 end
58
59
59 def test_annotate
60 def test_annotate
60 annotate = @adapter.annotate('sources/watchers_controller.rb')
61 annotate = @adapter.annotate('sources/watchers_controller.rb')
61 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
62 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
62 assert_equal 41, annotate.lines.size
63 assert_equal 41, annotate.lines.size
63 assert_equal "# This program is free software; you can redistribute it and/or", annotate.lines[4].strip
64 assert_equal "# This program is free software; you can redistribute it and/or", annotate.lines[4].strip
64 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
65 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
65 annotate.revisions[4].identifier
66 annotate.revisions[4].identifier
66 assert_equal "jsmith", annotate.revisions[4].author
67 assert_equal "jsmith", annotate.revisions[4].author
67 end
68 end
68
69
69 def test_annotate_moved_file
70 def test_annotate_moved_file
70 annotate = @adapter.annotate('renamed_test.txt')
71 annotate = @adapter.annotate('renamed_test.txt')
71 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
72 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
72 assert_equal 2, annotate.lines.size
73 assert_equal 2, annotate.lines.size
73 end
74 end
74
75
75 def test_last_rev
76 def test_last_rev
76 last_rev = @adapter.lastrev("README",
77 last_rev = @adapter.lastrev("README",
77 "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
78 "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
78 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
79 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
79 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
80 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
80 assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
81 assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
81 assert_equal "2009-06-24 05:27:38".to_time, last_rev.time
82 assert_equal "2009-06-24 05:27:38".to_time, last_rev.time
82 end
83 end
83
84
84 def test_last_rev_with_spaces_in_filename
85 def test_last_rev_with_spaces_in_filename
85 last_rev = @adapter.lastrev("filemane with spaces.txt",
86 last_rev = @adapter.lastrev("filemane with spaces.txt",
86 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
87 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
87 str_felix_utf8 = FELIX_UTF8
88 str_felix_utf8 = FELIX_UTF8
88 str_felix_hex = FELIX_HEX
89 str_felix_hex = FELIX_HEX
89 last_rev_author = last_rev.author
90 last_rev_author = last_rev.author
90 if last_rev_author.respond_to?(:force_encoding)
91 if last_rev_author.respond_to?(:force_encoding)
91 last_rev_author.force_encoding('UTF-8')
92 last_rev_author.force_encoding('UTF-8')
92 end
93 end
93 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
94 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
94 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
95 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
95 assert_equal "#{str_felix_utf8} <felix@fachschaften.org>",
96 assert_equal "#{str_felix_utf8} <felix@fachschaften.org>",
96 last_rev.author
97 last_rev.author
97 assert_equal "#{str_felix_hex} <felix@fachschaften.org>",
98 assert_equal "#{str_felix_hex} <felix@fachschaften.org>",
98 last_rev.author
99 last_rev.author
99 assert_equal "2010-09-18 19:59:46".to_time, last_rev.time
100 assert_equal "2010-09-18 19:59:46".to_time, last_rev.time
100 end
101 end
101
102
102 private
103 private
103
104
104 def test_scm_version_for(scm_command_version, version)
105 def test_scm_version_for(scm_command_version, version)
105 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
106 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
106 assert_equal version, @adapter.class.scm_command_version
107 assert_equal version, @adapter.class.scm_command_version
107 end
108 end
108
109
109 else
110 else
110 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
111 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
111 def test_fake; assert true end
112 def test_fake; assert true end
112 end
113 end
113 end
114 end
114
115
115 rescue LoadError
116 rescue LoadError
116 class GitMochaFake < ActiveSupport::TestCase
117 class GitMochaFake < ActiveSupport::TestCase
117 def test_fake; assert(false, "Requires mocha to run those tests") end
118 def test_fake; assert(false, "Requires mocha to run those tests") end
118 end
119 end
119 end
120 end
120
121
@@ -1,135 +1,135
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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
19
20 class RepositoryGitTest < ActiveSupport::TestCase
20 class RepositoryGitTest < ActiveSupport::TestCase
21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22
22
23 # No '..' in the repository path
23 # No '..' in the repository path
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
25 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
25 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
26
26
27 FELIX_HEX = "Felix Sch\xC3\xA4fer"
27 FELIX_HEX = "Felix Sch\xC3\xA4fer"
28
28
29 def setup
29 def setup
30 Setting.commit_logs_encoding = 'UTF-8'
30 Setting.commit_logs_encoding = 'UTF-8'
31 @project = Project.find(3)
31 @project = Project.find(3)
32 @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH)
32 @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH)
33 assert @repository
33 assert @repository
34 end
34 end
35
35
36 if File.directory?(REPOSITORY_PATH)
36 if File.directory?(REPOSITORY_PATH)
37 def test_fetch_changesets_from_scratch
37 def test_fetch_changesets_from_scratch
38 @repository.fetch_changesets
38 @repository.fetch_changesets
39 @repository.reload
39 @repository.reload
40
40
41 assert_equal 16, @repository.changesets.count
41 assert_equal 21, @repository.changesets.count
42 assert_equal 25, @repository.changes.count
42 assert_equal 31, @repository.changes.count
43
43
44 commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
44 commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
45 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
45 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
46 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
46 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
47 assert_equal User.find_by_login('jsmith'), commit.user
47 assert_equal User.find_by_login('jsmith'), commit.user
48 # TODO: add a commit with commit time <> author time to the test repository
48 # TODO: add a commit with commit time <> author time to the test repository
49 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
49 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
50 assert_equal "2007-12-14".to_date, commit.commit_date
50 assert_equal "2007-12-14".to_date, commit.commit_date
51 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision
51 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision
52 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
52 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
53 assert_equal 3, commit.changes.count
53 assert_equal 3, commit.changes.count
54 change = commit.changes.sort_by(&:path).first
54 change = commit.changes.sort_by(&:path).first
55 assert_equal "README", change.path
55 assert_equal "README", change.path
56 assert_equal "A", change.action
56 assert_equal "A", change.action
57 end
57 end
58
58
59 def test_fetch_changesets_incremental
59 def test_fetch_changesets_incremental
60 @repository.fetch_changesets
60 @repository.fetch_changesets
61 # Remove the 3 latest changesets
61 # Remove the 3 latest changesets
62 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
62 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 8).each(&:destroy)
63 @repository.reload
63 @repository.reload
64 cs1 = @repository.changesets
64 cs1 = @repository.changesets
65 assert_equal 13, cs1.count
65 assert_equal 13, cs1.count
66
66
67 rev_a_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
67 rev_a_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
68 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision
68 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision
69 # Mon Jul 5 22:34:26 2010 +0200
69 # Mon Jul 5 22:34:26 2010 +0200
70 rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26)
70 rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26)
71 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid
71 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid
72 assert_equal rev_a_committed_on, rev_a_commit.committed_on
72 assert_equal rev_a_committed_on, rev_a_commit.committed_on
73 latest_rev = @repository.latest_changeset
73 latest_rev = @repository.latest_changeset
74 assert_equal rev_a_committed_on, latest_rev.committed_on
74 assert_equal rev_a_committed_on, latest_rev.committed_on
75
75
76 @repository.fetch_changesets
76 @repository.fetch_changesets
77 assert_equal 16, @repository.changesets.count
77 assert_equal 21, @repository.changesets.count
78 end
78 end
79
79
80 def test_find_changeset_by_name
80 def test_find_changeset_by_name
81 @repository.fetch_changesets
81 @repository.fetch_changesets
82 @repository.reload
82 @repository.reload
83 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
83 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
84 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
84 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
85 @repository.find_changeset_by_name(r).revision
85 @repository.find_changeset_by_name(r).revision
86 end
86 end
87 end
87 end
88
88
89 def test_find_changeset_by_empty_name
89 def test_find_changeset_by_empty_name
90 @repository.fetch_changesets
90 @repository.fetch_changesets
91 @repository.reload
91 @repository.reload
92 ['', ' ', nil].each do |r|
92 ['', ' ', nil].each do |r|
93 assert_nil @repository.find_changeset_by_name(r)
93 assert_nil @repository.find_changeset_by_name(r)
94 end
94 end
95 end
95 end
96
96
97 def test_identifier
97 def test_identifier
98 @repository.fetch_changesets
98 @repository.fetch_changesets
99 @repository.reload
99 @repository.reload
100 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
100 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
101 assert_equal c.scmid, c.identifier
101 assert_equal c.scmid, c.identifier
102 end
102 end
103
103
104 def test_format_identifier
104 def test_format_identifier
105 @repository.fetch_changesets
105 @repository.fetch_changesets
106 @repository.reload
106 @repository.reload
107 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
107 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
108 assert_equal '7234cb27', c.format_identifier
108 assert_equal '7234cb27', c.format_identifier
109 end
109 end
110
110
111 def test_activities
111 def test_activities
112 c = Changeset.new(:repository => @repository,
112 c = Changeset.new(:repository => @repository,
113 :committed_on => Time.now,
113 :committed_on => Time.now,
114 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
114 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
115 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
115 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
116 :comments => 'test')
116 :comments => 'test')
117 assert c.event_title.include?('abc7234c:')
117 assert c.event_title.include?('abc7234c:')
118 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
118 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
119 end
119 end
120
120
121 def test_log_utf8
121 def test_log_utf8
122 @repository.fetch_changesets
122 @repository.fetch_changesets
123 @repository.reload
123 @repository.reload
124 str_felix_hex = FELIX_HEX
124 str_felix_hex = FELIX_HEX
125 if str_felix_hex.respond_to?(:force_encoding)
125 if str_felix_hex.respond_to?(:force_encoding)
126 str_felix_hex.force_encoding('UTF-8')
126 str_felix_hex.force_encoding('UTF-8')
127 end
127 end
128 c = @repository.changesets.find_by_revision('ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
128 c = @repository.changesets.find_by_revision('ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
129 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
129 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
130 end
130 end
131 else
131 else
132 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
132 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
133 def test_fake; assert true end
133 def test_fake; assert true end
134 end
134 end
135 end
135 end
General Comments 0
You need to be logged in to leave comments. Login now