##// END OF EJS Templates
Fix subversion and git activities test reffering r4621....
Toshi MARUYAMA -
r4503:8487e0a5b83f
parent child
Show More
@@ -1,95 +1,92
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 def setup
27 def setup
28 @project = Project.find(1)
28 @project = Project.find(1)
29 assert @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH)
29 assert @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH)
30 end
30 end
31
31
32 if File.directory?(REPOSITORY_PATH)
32 if File.directory?(REPOSITORY_PATH)
33 def test_fetch_changesets_from_scratch
33 def test_fetch_changesets_from_scratch
34 @repository.fetch_changesets
34 @repository.fetch_changesets
35 @repository.reload
35 @repository.reload
36
36
37 assert_equal 15, @repository.changesets.count
37 assert_equal 15, @repository.changesets.count
38 assert_equal 24, @repository.changes.count
38 assert_equal 24, @repository.changes.count
39
39
40 commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
40 commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
41 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
41 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
42 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
42 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
43 assert_equal User.find_by_login('jsmith'), commit.user
43 assert_equal User.find_by_login('jsmith'), commit.user
44 # TODO: add a commit with commit time <> author time to the test repository
44 # TODO: add a commit with commit time <> author time to the test repository
45 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
45 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
46 assert_equal "2007-12-14".to_date, commit.commit_date
46 assert_equal "2007-12-14".to_date, commit.commit_date
47 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision
47 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision
48 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
48 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
49 assert_equal 3, commit.changes.count
49 assert_equal 3, commit.changes.count
50 change = commit.changes.sort_by(&:path).first
50 change = commit.changes.sort_by(&:path).first
51 assert_equal "README", change.path
51 assert_equal "README", change.path
52 assert_equal "A", change.action
52 assert_equal "A", change.action
53 end
53 end
54
54
55 def test_fetch_changesets_incremental
55 def test_fetch_changesets_incremental
56 @repository.fetch_changesets
56 @repository.fetch_changesets
57 # Remove the 3 latest changesets
57 # Remove the 3 latest changesets
58 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
58 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
59 @repository.reload
59 @repository.reload
60 assert_equal 12, @repository.changesets.count
60 assert_equal 12, @repository.changesets.count
61
61
62 @repository.fetch_changesets
62 @repository.fetch_changesets
63 assert_equal 15, @repository.changesets.count
63 assert_equal 15, @repository.changesets.count
64 end
64 end
65
65
66 def test_identifier
66 def test_identifier
67 @repository.fetch_changesets
67 @repository.fetch_changesets
68 @repository.reload
68 @repository.reload
69 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
69 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
70 assert_equal c.scmid, c.identifier
70 assert_equal c.scmid, c.identifier
71 end
71 end
72
72
73 def test_format_identifier
73 def test_format_identifier
74 @repository.fetch_changesets
74 @repository.fetch_changesets
75 @repository.reload
75 @repository.reload
76 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
76 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
77 assert_equal c.format_identifier, '7234cb27'
77 assert_equal c.format_identifier, '7234cb27'
78 end
78 end
79
79
80 def test_activities
80 def test_activities
81 @repository.fetch_changesets
81 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
82 @repository.reload
82 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
83 f = Redmine::Activity::Fetcher.new(User.anonymous, :project => Project.find(1))
83 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
84 f.scope = ['changesets']
84 :comments => 'test')
85 events = f.events
85 assert c.event_title.include?('abc7234c:')
86 assert_kind_of Array, events
86 assert_equal c.event_url[:rev], 'abc7234cb2750b63f47bff735edc50a1c0a433c2'
87 eve = events[-9]
88 assert eve.event_title.include?('7234cb27:')
89 assert_equal eve.event_url[:rev], '7234cb2750b63f47bff735edc50a1c0a433c2518'
90 end
87 end
91 else
88 else
92 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
89 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
93 def test_fake; assert true end
90 def test_fake; assert true end
94 end
91 end
95 end
92 end
@@ -1,137 +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 RepositorySubversionTest < ActiveSupport::TestCase
20 class RepositorySubversionTest < ActiveSupport::TestCase
21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22
22
23 def setup
23 def setup
24 @project = Project.find(1)
24 @project = Project.find(1)
25 assert @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{self.class.repository_path('subversion')}")
25 assert @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{self.class.repository_path('subversion')}")
26 end
26 end
27
27
28 if repository_configured?('subversion')
28 if repository_configured?('subversion')
29 def test_fetch_changesets_from_scratch
29 def test_fetch_changesets_from_scratch
30 @repository.fetch_changesets
30 @repository.fetch_changesets
31 @repository.reload
31 @repository.reload
32
32
33 assert_equal 11, @repository.changesets.count
33 assert_equal 11, @repository.changesets.count
34 assert_equal 20, @repository.changes.count
34 assert_equal 20, @repository.changes.count
35 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
35 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
36 end
36 end
37
37
38 def test_fetch_changesets_incremental
38 def test_fetch_changesets_incremental
39 @repository.fetch_changesets
39 @repository.fetch_changesets
40 # Remove changesets with revision > 5
40 # Remove changesets with revision > 5
41 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5}
41 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5}
42 @repository.reload
42 @repository.reload
43 assert_equal 5, @repository.changesets.count
43 assert_equal 5, @repository.changesets.count
44
44
45 @repository.fetch_changesets
45 @repository.fetch_changesets
46 assert_equal 11, @repository.changesets.count
46 assert_equal 11, @repository.changesets.count
47 end
47 end
48
48
49 def test_latest_changesets
49 def test_latest_changesets
50 @repository.fetch_changesets
50 @repository.fetch_changesets
51
51
52 # with limit
52 # with limit
53 changesets = @repository.latest_changesets('', nil, 2)
53 changesets = @repository.latest_changesets('', nil, 2)
54 assert_equal 2, changesets.size
54 assert_equal 2, changesets.size
55 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
55 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
56
56
57 # with path
57 # with path
58 changesets = @repository.latest_changesets('subversion_test/folder', nil)
58 changesets = @repository.latest_changesets('subversion_test/folder', nil)
59 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
59 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
60
60
61 # with path and revision
61 # with path and revision
62 changesets = @repository.latest_changesets('subversion_test/folder', 8)
62 changesets = @repository.latest_changesets('subversion_test/folder', 8)
63 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
63 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
64 end
64 end
65
65
66 def test_directory_listing_with_square_brackets_in_path
66 def test_directory_listing_with_square_brackets_in_path
67 @repository.fetch_changesets
67 @repository.fetch_changesets
68 @repository.reload
68 @repository.reload
69
69
70 entries = @repository.entries('subversion_test/[folder_with_brackets]')
70 entries = @repository.entries('subversion_test/[folder_with_brackets]')
71 assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
71 assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
72 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
72 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
73 assert_equal 'README.txt', entries.first.name
73 assert_equal 'README.txt', entries.first.name
74 end
74 end
75
75
76 def test_directory_listing_with_square_brackets_in_base
76 def test_directory_listing_with_square_brackets_in_base
77 @project = Project.find(1)
77 @project = Project.find(1)
78 @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
78 @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
79
79
80 @repository.fetch_changesets
80 @repository.fetch_changesets
81 @repository.reload
81 @repository.reload
82
82
83 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
83 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
84 assert_equal 2, @repository.changes.count, 'Expected to see 2 changes, dir add and file add'
84 assert_equal 2, @repository.changes.count, 'Expected to see 2 changes, dir add and file add'
85
85
86 entries = @repository.entries('')
86 entries = @repository.entries('')
87 assert_not_nil entries, 'Expect to find entries'
87 assert_not_nil entries, 'Expect to find entries'
88 assert_equal 1, entries.size, 'Expect a single entry'
88 assert_equal 1, entries.size, 'Expect a single entry'
89 assert_equal 'README.txt', entries.first.name
89 assert_equal 'README.txt', entries.first.name
90 end
90 end
91
91
92 def test_identifier
92 def test_identifier
93 @repository.fetch_changesets
93 @repository.fetch_changesets
94 @repository.reload
94 @repository.reload
95 c = @repository.changesets.find_by_revision('1')
95 c = @repository.changesets.find_by_revision('1')
96 assert_equal c.revision, c.identifier
96 assert_equal c.revision, c.identifier
97 end
97 end
98
98
99 def test_identifier_nine_digit
99 def test_identifier_nine_digit
100 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
100 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
101 :revision => '123456789', :comments => 'test')
101 :revision => '123456789', :comments => 'test')
102 assert_equal c.identifier, c.revision
102 assert_equal c.identifier, c.revision
103 end
103 end
104
104
105 def test_format_identifier
105 def test_format_identifier
106 @repository.fetch_changesets
106 @repository.fetch_changesets
107 @repository.reload
107 @repository.reload
108 c = @repository.changesets.find_by_revision('1')
108 c = @repository.changesets.find_by_revision('1')
109 assert_equal c.format_identifier, c.revision
109 assert_equal c.format_identifier, c.revision
110 end
110 end
111
111
112 def test_format_identifier_nine_digit
112 def test_format_identifier_nine_digit
113 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
113 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
114 :revision => '123456789', :comments => 'test')
114 :revision => '123456789', :comments => 'test')
115 assert_equal c.format_identifier, c.revision
115 assert_equal c.format_identifier, c.revision
116 end
116 end
117
117
118 def test_activities
118 def test_activities
119 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
119 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
120 :revision => '1', :comments => 'test')
120 :revision => '1', :comments => 'test')
121
121 assert c.event_title.include?('1:')
122 assert c.event_title.include?('1:'), c.event_title
123 assert_equal c.event_url[:rev], '1'
122 assert_equal c.event_url[:rev], '1'
124 end
123 end
125
124
126 def test_activities_nine_digit
125 def test_activities_nine_digit
127 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
126 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
128 :revision => '123456789', :comments => 'test')
127 :revision => '123456789', :comments => 'test')
129
130 assert c.event_title.include?('123456789:')
128 assert c.event_title.include?('123456789:')
131 assert_equal c.event_url[:rev], '123456789'
129 assert_equal c.event_url[:rev], '123456789'
132 end
130 end
133 else
131 else
134 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
132 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
135 def test_fake; assert true end
133 def test_fake; assert true end
136 end
134 end
137 end
135 end
General Comments 0
You need to be logged in to leave comments. Login now