##// 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 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class RepositoryGitTest < ActiveSupport::TestCase
20 class RepositoryGitTest < ActiveSupport::TestCase
21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22
22
23 # No '..' in the repository path
23 # No '..' in the repository path
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
25 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
25 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
26
26
27 FELIX_HEX = "Felix Sch\xC3\xA4fer"
28
27 def setup
29 def setup
30 Setting.commit_logs_encoding = 'UTF-8'
28 @project = Project.find(3)
31 @project = Project.find(3)
29 @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH)
32 @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH)
30 assert @repository
33 assert @repository
31 end
34 end
32
35
33 if File.directory?(REPOSITORY_PATH)
36 if File.directory?(REPOSITORY_PATH)
34 def test_fetch_changesets_from_scratch
37 def test_fetch_changesets_from_scratch
35 @repository.fetch_changesets
38 @repository.fetch_changesets
36 @repository.reload
39 @repository.reload
37
40
38 assert_equal 15, @repository.changesets.count
41 assert_equal 15, @repository.changesets.count
39 assert_equal 24, @repository.changes.count
42 assert_equal 24, @repository.changes.count
40
43
41 commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
44 commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
42 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
45 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
43 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
46 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
44 assert_equal User.find_by_login('jsmith'), commit.user
47 assert_equal User.find_by_login('jsmith'), commit.user
45 # TODO: add a commit with commit time <> author time to the test repository
48 # TODO: add a commit with commit time <> author time to the test repository
46 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
49 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
47 assert_equal "2007-12-14".to_date, commit.commit_date
50 assert_equal "2007-12-14".to_date, commit.commit_date
48 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision
51 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision
49 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
52 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
50 assert_equal 3, commit.changes.count
53 assert_equal 3, commit.changes.count
51 change = commit.changes.sort_by(&:path).first
54 change = commit.changes.sort_by(&:path).first
52 assert_equal "README", change.path
55 assert_equal "README", change.path
53 assert_equal "A", change.action
56 assert_equal "A", change.action
54 end
57 end
55
58
56 def test_fetch_changesets_incremental
59 def test_fetch_changesets_incremental
57 @repository.fetch_changesets
60 @repository.fetch_changesets
58 # Remove the 3 latest changesets
61 # Remove the 3 latest changesets
59 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
62 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
60 @repository.reload
63 @repository.reload
61 assert_equal 12, @repository.changesets.count
64 assert_equal 12, @repository.changesets.count
62
65
63 @repository.fetch_changesets
66 @repository.fetch_changesets
64 assert_equal 15, @repository.changesets.count
67 assert_equal 15, @repository.changesets.count
65 end
68 end
66
69
67 def test_find_changeset_by_name
70 def test_find_changeset_by_name
68 @repository.fetch_changesets
71 @repository.fetch_changesets
69 @repository.reload
72 @repository.reload
70 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
73 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
71 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
74 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
72 @repository.find_changeset_by_name(r).revision
75 @repository.find_changeset_by_name(r).revision
73 end
76 end
74 end
77 end
75
78
76 def test_find_changeset_by_empty_name
79 def test_find_changeset_by_empty_name
77 @repository.fetch_changesets
80 @repository.fetch_changesets
78 @repository.reload
81 @repository.reload
79 ['', ' ', nil].each do |r|
82 ['', ' ', nil].each do |r|
80 assert_nil @repository.find_changeset_by_name(r)
83 assert_nil @repository.find_changeset_by_name(r)
81 end
84 end
82 end
85 end
83
86
84 def test_identifier
87 def test_identifier
85 @repository.fetch_changesets
88 @repository.fetch_changesets
86 @repository.reload
89 @repository.reload
87 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
90 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
88 assert_equal c.scmid, c.identifier
91 assert_equal c.scmid, c.identifier
89 end
92 end
90
93
91 def test_format_identifier
94 def test_format_identifier
92 @repository.fetch_changesets
95 @repository.fetch_changesets
93 @repository.reload
96 @repository.reload
94 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
97 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
95 assert_equal '7234cb27', c.format_identifier
98 assert_equal '7234cb27', c.format_identifier
96 end
99 end
97
100
98 def test_activities
101 def test_activities
99 c = Changeset.new(:repository => @repository,
102 c = Changeset.new(:repository => @repository,
100 :committed_on => Time.now,
103 :committed_on => Time.now,
101 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
104 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
102 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
105 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
103 :comments => 'test')
106 :comments => 'test')
104 assert c.event_title.include?('abc7234c:')
107 assert c.event_title.include?('abc7234c:')
105 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
108 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
106 end
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 else
121 else
108 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
122 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
109 def test_fake; assert true end
123 def test_fake; assert true end
110 end
124 end
111 end
125 end
General Comments 0
You need to be logged in to leave comments. Login now