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