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