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