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