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