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