##// END OF EJS Templates
scm: code clean up unit repository test....
Toshi MARUYAMA -
r5538:c33be450e718
parent child
Show More
@@ -1,192 +1,192
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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 RepositoryTest < ActiveSupport::TestCase
20 class RepositoryTest < ActiveSupport::TestCase
21 fixtures :projects,
21 fixtures :projects,
22 :trackers,
22 :trackers,
23 :projects_trackers,
23 :projects_trackers,
24 :enabled_modules,
24 :enabled_modules,
25 :repositories,
25 :repositories,
26 :issues,
26 :issues,
27 :issue_statuses,
27 :issue_statuses,
28 :issue_categories,
28 :issue_categories,
29 :changesets,
29 :changesets,
30 :changes,
30 :changes,
31 :users,
31 :users,
32 :members,
32 :members,
33 :member_roles,
33 :member_roles,
34 :roles,
34 :roles,
35 :enumerations
35 :enumerations
36
36
37 def setup
37 def setup
38 @repository = Project.find(1).repository
38 @repository = Project.find(1).repository
39 end
39 end
40
40
41 def test_create
41 def test_create
42 repository = Repository::Subversion.new(:project => Project.find(3))
42 repository = Repository::Subversion.new(:project => Project.find(3))
43 assert !repository.save
43 assert !repository.save
44
44
45 repository.url = "svn://localhost"
45 repository.url = "svn://localhost"
46 assert repository.save
46 assert repository.save
47 repository.reload
47 repository.reload
48
48
49 project = Project.find(3)
49 project = Project.find(3)
50 assert_equal repository, project.repository
50 assert_equal repository, project.repository
51 end
51 end
52
52
53 def test_destroy
53 def test_destroy
54 changesets = Changeset.count(:all, :conditions => "repository_id = 10")
54 changesets = Changeset.count(:all, :conditions => "repository_id = 10")
55 changes = Change.count(:all, :conditions => "repository_id = 10", :include => :changeset)
55 changes = Change.count(:all, :conditions => "repository_id = 10", :include => :changeset)
56 assert_difference 'Changeset.count', -changesets do
56 assert_difference 'Changeset.count', -changesets do
57 assert_difference 'Change.count', -changes do
57 assert_difference 'Change.count', -changes do
58 Repository.find(10).destroy
58 Repository.find(10).destroy
59 end
59 end
60 end
60 end
61 end
61 end
62
62
63 def test_should_not_create_with_disabled_scm
63 def test_should_not_create_with_disabled_scm
64 # disable Subversion
64 # disable Subversion
65 with_settings :enabled_scm => ['Darcs', 'Git'] do
65 with_settings :enabled_scm => ['Darcs', 'Git'] do
66 repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost")
66 repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost")
67 assert !repository.save
67 assert !repository.save
68 assert_equal I18n.translate('activerecord.errors.messages.invalid'), repository.errors.on(:type)
68 assert_equal I18n.translate('activerecord.errors.messages.invalid'), repository.errors.on(:type)
69 end
69 end
70 end
70 end
71
71
72 def test_scan_changesets_for_issue_ids
72 def test_scan_changesets_for_issue_ids
73 Setting.default_language = 'en'
73 Setting.default_language = 'en'
74 Setting.notified_events = ['issue_added','issue_updated']
74 Setting.notified_events = ['issue_added','issue_updated']
75
75
76 # choosing a status to apply to fix issues
76 # choosing a status to apply to fix issues
77 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
77 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
78 Setting.commit_fix_done_ratio = "90"
78 Setting.commit_fix_done_ratio = "90"
79 Setting.commit_ref_keywords = 'refs , references, IssueID'
79 Setting.commit_ref_keywords = 'refs , references, IssueID'
80 Setting.commit_fix_keywords = 'fixes , closes'
80 Setting.commit_fix_keywords = 'fixes , closes'
81 Setting.default_language = 'en'
81 Setting.default_language = 'en'
82 ActionMailer::Base.deliveries.clear
82 ActionMailer::Base.deliveries.clear
83
83
84 # make sure issue 1 is not already closed
84 # make sure issue 1 is not already closed
85 fixed_issue = Issue.find(1)
85 fixed_issue = Issue.find(1)
86 assert !fixed_issue.status.is_closed?
86 assert !fixed_issue.status.is_closed?
87 old_status = fixed_issue.status
87 old_status = fixed_issue.status
88
88
89 Repository.scan_changesets_for_issue_ids
89 Repository.scan_changesets_for_issue_ids
90 assert_equal [101, 102], Issue.find(3).changeset_ids
90 assert_equal [101, 102], Issue.find(3).changeset_ids
91
91
92 # fixed issues
92 # fixed issues
93 fixed_issue.reload
93 fixed_issue.reload
94 assert fixed_issue.status.is_closed?
94 assert fixed_issue.status.is_closed?
95 assert_equal 90, fixed_issue.done_ratio
95 assert_equal 90, fixed_issue.done_ratio
96 assert_equal [101], fixed_issue.changeset_ids
96 assert_equal [101], fixed_issue.changeset_ids
97
97
98 # issue change
98 # issue change
99 journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
99 journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
100 assert_equal User.find_by_login('dlopper'), journal.user
100 assert_equal User.find_by_login('dlopper'), journal.user
101 assert_equal 'Applied in changeset r2.', journal.notes
101 assert_equal 'Applied in changeset r2.', journal.notes
102
102
103 # 2 email notifications
103 # 2 email notifications
104 assert_equal 2, ActionMailer::Base.deliveries.size
104 assert_equal 2, ActionMailer::Base.deliveries.size
105 mail = ActionMailer::Base.deliveries.first
105 mail = ActionMailer::Base.deliveries.first
106 assert_kind_of TMail::Mail, mail
106 assert_kind_of TMail::Mail, mail
107 assert mail.subject.starts_with?("[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
107 assert mail.subject.starts_with?("[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
108 assert mail.body.include?("Status changed from #{old_status} to #{fixed_issue.status}")
108 assert mail.body.include?("Status changed from #{old_status} to #{fixed_issue.status}")
109
109
110 # ignoring commits referencing an issue of another project
110 # ignoring commits referencing an issue of another project
111 assert_equal [], Issue.find(4).changesets
111 assert_equal [], Issue.find(4).changesets
112 end
112 end
113
113
114 def test_for_changeset_comments_strip
114 def test_for_changeset_comments_strip
115 repository = Repository::Mercurial.create( :project => Project.find( 4 ), :url => '/foo/bar/baz' )
115 repository = Repository::Mercurial.create( :project => Project.find( 4 ), :url => '/foo/bar/baz' )
116 comment = <<-COMMENT
116 comment = <<-COMMENT
117 This is a loooooooooooooooooooooooooooong comment
117 This is a loooooooooooooooooooooooooooong comment
118
118
119
119
120 COMMENT
120 COMMENT
121 changeset = Changeset.new(
121 changeset = Changeset.new(
122 :comments => comment, :commit_date => Time.now, :revision => 0, :scmid => 'f39b7922fb3c',
122 :comments => comment, :commit_date => Time.now, :revision => 0, :scmid => 'f39b7922fb3c',
123 :committer => 'foo <foo@example.com>', :committed_on => Time.now, :repository => repository )
123 :committer => 'foo <foo@example.com>', :committed_on => Time.now, :repository => repository )
124 assert( changeset.save )
124 assert( changeset.save )
125 assert_not_equal( comment, changeset.comments )
125 assert_not_equal( comment, changeset.comments )
126 assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments )
126 assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments )
127 end
127 end
128
128
129 def test_for_urls_strip
129 def test_for_urls_strip
130 repository = Repository::Cvs.create(
130 repository = Repository::Cvs.create(
131 :project => Project.find(4),
131 :project => Project.find(4),
132 :url => ' :pserver:login:password@host:/path/to/the/repository',
132 :url => ' :pserver:login:password@host:/path/to/the/repository',
133 :root_url => 'foo ',
133 :root_url => 'foo ',
134 :log_encoding => 'UTF-8')
134 :log_encoding => 'UTF-8')
135 assert repository.save
135 assert repository.save
136 repository.reload
136 repository.reload
137 assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url
137 assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url
138 assert_equal 'foo', repository.root_url
138 assert_equal 'foo', repository.root_url
139 end
139 end
140
140
141 def test_manual_user_mapping
141 def test_manual_user_mapping
142 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
142 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
143 c = Changeset.create!(
143 c = Changeset.create!(
144 :repository => @repository,
144 :repository => @repository,
145 :committer => 'foo',
145 :committer => 'foo',
146 :committed_on => Time.now,
146 :committed_on => Time.now,
147 :revision => 100,
147 :revision => 100,
148 :comments => 'Committed by foo.'
148 :comments => 'Committed by foo.'
149 )
149 )
150 assert_nil c.user
150 assert_nil c.user
151 @repository.committer_ids = {'foo' => '2'}
151 @repository.committer_ids = {'foo' => '2'}
152 assert_equal User.find(2), c.reload.user
152 assert_equal User.find(2), c.reload.user
153 # committer is now mapped
153 # committer is now mapped
154 c = Changeset.create!(
154 c = Changeset.create!(
155 :repository => @repository,
155 :repository => @repository,
156 :committer => 'foo',
156 :committer => 'foo',
157 :committed_on => Time.now,
157 :committed_on => Time.now,
158 :revision => 101,
158 :revision => 101,
159 :comments => 'Another commit by foo.'
159 :comments => 'Another commit by foo.'
160 )
160 )
161 assert_equal User.find(2), c.user
161 assert_equal User.find(2), c.user
162 end
162 end
163 end
163 end
164
164
165 def test_auto_user_mapping_by_username
165 def test_auto_user_mapping_by_username
166 c = Changeset.create!(
166 c = Changeset.create!(
167 :repository => @repository,
167 :repository => @repository,
168 :committer => 'jsmith',
168 :committer => 'jsmith',
169 :committed_on => Time.now,
169 :committed_on => Time.now,
170 :revision => 100,
170 :revision => 100,
171 :comments => 'Committed by john.'
171 :comments => 'Committed by john.'
172 )
172 )
173 assert_equal User.find(2), c.user
173 assert_equal User.find(2), c.user
174 end
174 end
175
175
176 def test_auto_user_mapping_by_email
176 def test_auto_user_mapping_by_email
177 c = Changeset.create!(
177 c = Changeset.create!(
178 :repository => @repository,
178 :repository => @repository,
179 :committer => 'john <jsmith@somenet.foo>',
179 :committer => 'john <jsmith@somenet.foo>',
180 :committed_on => Time.now,
180 :committed_on => Time.now,
181 :revision => 100,
181 :revision => 100,
182 :comments => 'Committed by john.'
182 :comments => 'Committed by john.'
183 )
183 )
184 assert_equal User.find(2), c.user
184 assert_equal User.find(2), c.user
185 end
185 end
186
186
187 def test_filesystem_avaialbe
187 def test_filesystem_avaialbe
188 klass = Repository::Filesystem
188 klass = Repository::Filesystem
189 assert klass.scm_adapter_class
189 assert klass.scm_adapter_class
190 assert_equal true, klass.scm_available
190 assert_equal true, klass.scm_available
191 end
191 end
192 end
192 end
General Comments 0
You need to be logged in to leave comments. Login now