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