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