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