@@ -1,135 +1,139 | |||||
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( |
|
32 | @repository = Repository::Git.create( | |
|
33 | :project => @project, | |||
|
34 | :url => REPOSITORY_PATH, | |||
|
35 | :path_encoding => 'ISO-8859-1' | |||
|
36 | ) | |||
33 | assert @repository |
|
37 | assert @repository | |
34 | end |
|
38 | end | |
35 |
|
39 | |||
36 | if File.directory?(REPOSITORY_PATH) |
|
40 | if File.directory?(REPOSITORY_PATH) | |
37 | def test_fetch_changesets_from_scratch |
|
41 | def test_fetch_changesets_from_scratch | |
38 | @repository.fetch_changesets |
|
42 | @repository.fetch_changesets | |
39 | @repository.reload |
|
43 | @repository.reload | |
40 |
|
44 | |||
41 | assert_equal 20, @repository.changesets.count |
|
45 | assert_equal 20, @repository.changesets.count | |
42 | assert_equal 30, @repository.changes.count |
|
46 | assert_equal 30, @repository.changes.count | |
43 |
|
47 | |||
44 | commit = @repository.changesets.find(:first, :order => 'committed_on ASC') |
|
48 | commit = @repository.changesets.find(:first, :order => 'committed_on ASC') | |
45 | assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments |
|
49 | assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments | |
46 | assert_equal "jsmith <jsmith@foo.bar>", commit.committer |
|
50 | assert_equal "jsmith <jsmith@foo.bar>", commit.committer | |
47 | assert_equal User.find_by_login('jsmith'), commit.user |
|
51 | assert_equal User.find_by_login('jsmith'), commit.user | |
48 | # TODO: add a commit with commit time <> author time to the test repository |
|
52 | # 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 |
|
53 | assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on | |
50 | assert_equal "2007-12-14".to_date, commit.commit_date |
|
54 | assert_equal "2007-12-14".to_date, commit.commit_date | |
51 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision |
|
55 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision | |
52 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid |
|
56 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid | |
53 | assert_equal 3, commit.changes.count |
|
57 | assert_equal 3, commit.changes.count | |
54 | change = commit.changes.sort_by(&:path).first |
|
58 | change = commit.changes.sort_by(&:path).first | |
55 | assert_equal "README", change.path |
|
59 | assert_equal "README", change.path | |
56 | assert_equal "A", change.action |
|
60 | assert_equal "A", change.action | |
57 | end |
|
61 | end | |
58 |
|
62 | |||
59 | def test_fetch_changesets_incremental |
|
63 | def test_fetch_changesets_incremental | |
60 | @repository.fetch_changesets |
|
64 | @repository.fetch_changesets | |
61 | # Remove the 3 latest changesets |
|
65 | # Remove the 3 latest changesets | |
62 | @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 7).each(&:destroy) |
|
66 | @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 7).each(&:destroy) | |
63 | @repository.reload |
|
67 | @repository.reload | |
64 | cs1 = @repository.changesets |
|
68 | cs1 = @repository.changesets | |
65 | assert_equal 13, cs1.count |
|
69 | assert_equal 13, cs1.count | |
66 |
|
70 | |||
67 | rev_a_commit = @repository.changesets.find(:first, :order => 'committed_on DESC') |
|
71 | rev_a_commit = @repository.changesets.find(:first, :order => 'committed_on DESC') | |
68 | assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision |
|
72 | assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision | |
69 | # Mon Jul 5 22:34:26 2010 +0200 |
|
73 | # Mon Jul 5 22:34:26 2010 +0200 | |
70 | rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26) |
|
74 | rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26) | |
71 | assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid |
|
75 | assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid | |
72 | assert_equal rev_a_committed_on, rev_a_commit.committed_on |
|
76 | assert_equal rev_a_committed_on, rev_a_commit.committed_on | |
73 | latest_rev = @repository.latest_changeset |
|
77 | latest_rev = @repository.latest_changeset | |
74 | assert_equal rev_a_committed_on, latest_rev.committed_on |
|
78 | assert_equal rev_a_committed_on, latest_rev.committed_on | |
75 |
|
79 | |||
76 | @repository.fetch_changesets |
|
80 | @repository.fetch_changesets | |
77 | assert_equal 20, @repository.changesets.count |
|
81 | assert_equal 20, @repository.changesets.count | |
78 | end |
|
82 | end | |
79 |
|
83 | |||
80 | def test_find_changeset_by_name |
|
84 | def test_find_changeset_by_name | |
81 | @repository.fetch_changesets |
|
85 | @repository.fetch_changesets | |
82 | @repository.reload |
|
86 | @repository.reload | |
83 | ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r| |
|
87 | ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r| | |
84 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
88 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', | |
85 | @repository.find_changeset_by_name(r).revision |
|
89 | @repository.find_changeset_by_name(r).revision | |
86 | end |
|
90 | end | |
87 | end |
|
91 | end | |
88 |
|
92 | |||
89 | def test_find_changeset_by_empty_name |
|
93 | def test_find_changeset_by_empty_name | |
90 | @repository.fetch_changesets |
|
94 | @repository.fetch_changesets | |
91 | @repository.reload |
|
95 | @repository.reload | |
92 | ['', ' ', nil].each do |r| |
|
96 | ['', ' ', nil].each do |r| | |
93 | assert_nil @repository.find_changeset_by_name(r) |
|
97 | assert_nil @repository.find_changeset_by_name(r) | |
94 | end |
|
98 | end | |
95 | end |
|
99 | end | |
96 |
|
100 | |||
97 | def test_identifier |
|
101 | def test_identifier | |
98 | @repository.fetch_changesets |
|
102 | @repository.fetch_changesets | |
99 | @repository.reload |
|
103 | @repository.reload | |
100 | c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
104 | c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518') | |
101 | assert_equal c.scmid, c.identifier |
|
105 | assert_equal c.scmid, c.identifier | |
102 | end |
|
106 | end | |
103 |
|
107 | |||
104 | def test_format_identifier |
|
108 | def test_format_identifier | |
105 | @repository.fetch_changesets |
|
109 | @repository.fetch_changesets | |
106 | @repository.reload |
|
110 | @repository.reload | |
107 | c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
111 | c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518') | |
108 | assert_equal '7234cb27', c.format_identifier |
|
112 | assert_equal '7234cb27', c.format_identifier | |
109 | end |
|
113 | end | |
110 |
|
114 | |||
111 | def test_activities |
|
115 | def test_activities | |
112 | c = Changeset.new(:repository => @repository, |
|
116 | c = Changeset.new(:repository => @repository, | |
113 | :committed_on => Time.now, |
|
117 | :committed_on => Time.now, | |
114 | :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', |
|
118 | :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', | |
115 | :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', |
|
119 | :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', | |
116 | :comments => 'test') |
|
120 | :comments => 'test') | |
117 | assert c.event_title.include?('abc7234c:') |
|
121 | assert c.event_title.include?('abc7234c:') | |
118 | assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev] |
|
122 | assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev] | |
119 | end |
|
123 | end | |
120 |
|
124 | |||
121 | def test_log_utf8 |
|
125 | def test_log_utf8 | |
122 | @repository.fetch_changesets |
|
126 | @repository.fetch_changesets | |
123 | @repository.reload |
|
127 | @repository.reload | |
124 | str_felix_hex = FELIX_HEX |
|
128 | str_felix_hex = FELIX_HEX | |
125 | if str_felix_hex.respond_to?(:force_encoding) |
|
129 | if str_felix_hex.respond_to?(:force_encoding) | |
126 | str_felix_hex.force_encoding('UTF-8') |
|
130 | str_felix_hex.force_encoding('UTF-8') | |
127 | end |
|
131 | end | |
128 | c = @repository.changesets.find_by_revision('ed5bb786bbda2dee66a2d50faf51429dbc043a7b') |
|
132 | c = @repository.changesets.find_by_revision('ed5bb786bbda2dee66a2d50faf51429dbc043a7b') | |
129 | assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer |
|
133 | assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer | |
130 | end |
|
134 | end | |
131 | else |
|
135 | else | |
132 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
136 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" | |
133 | def test_fake; assert true end |
|
137 | def test_fake; assert true end | |
134 | end |
|
138 | end | |
135 | end |
|
139 | end |
General Comments 0
You need to be logged in to leave comments.
Login now