Chris@0
|
1 # redMine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@117
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19
|
Chris@0
|
20 class RepositoryTest < ActiveSupport::TestCase
|
Chris@0
|
21 fixtures :projects,
|
Chris@0
|
22 :trackers,
|
Chris@0
|
23 :projects_trackers,
|
Chris@117
|
24 :enabled_modules,
|
Chris@0
|
25 :repositories,
|
Chris@0
|
26 :issues,
|
Chris@0
|
27 :issue_statuses,
|
Chris@117
|
28 :issue_categories,
|
Chris@0
|
29 :changesets,
|
Chris@0
|
30 :changes,
|
Chris@0
|
31 :users,
|
Chris@117
|
32 :members,
|
Chris@117
|
33 :member_roles,
|
Chris@117
|
34 :roles,
|
Chris@0
|
35 :enumerations
|
Chris@0
|
36
|
Chris@0
|
37 def setup
|
Chris@0
|
38 @repository = Project.find(1).repository
|
Chris@0
|
39 end
|
Chris@0
|
40
|
Chris@0
|
41 def test_create
|
Chris@0
|
42 repository = Repository::Subversion.new(:project => Project.find(3))
|
Chris@0
|
43 assert !repository.save
|
Chris@0
|
44
|
Chris@0
|
45 repository.url = "svn://localhost"
|
Chris@0
|
46 assert repository.save
|
Chris@0
|
47 repository.reload
|
Chris@0
|
48
|
Chris@0
|
49 project = Project.find(3)
|
Chris@0
|
50 assert_equal repository, project.repository
|
Chris@0
|
51 end
|
Chris@0
|
52
|
Chris@0
|
53 def test_destroy
|
Chris@0
|
54 changesets = Changeset.count(:all, :conditions => "repository_id = 10")
|
Chris@0
|
55 changes = Change.count(:all, :conditions => "repository_id = 10", :include => :changeset)
|
Chris@0
|
56 assert_difference 'Changeset.count', -changesets do
|
Chris@0
|
57 assert_difference 'Change.count', -changes do
|
Chris@0
|
58 Repository.find(10).destroy
|
Chris@0
|
59 end
|
Chris@0
|
60 end
|
Chris@0
|
61 end
|
Chris@0
|
62
|
Chris@0
|
63 def test_should_not_create_with_disabled_scm
|
Chris@0
|
64 # disable Subversion
|
Chris@0
|
65 Setting.enabled_scm = ['Darcs', 'Git']
|
Chris@0
|
66 repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost")
|
Chris@0
|
67 assert !repository.save
|
Chris@0
|
68 assert_equal I18n.translate('activerecord.errors.messages.invalid'), repository.errors.on(:type)
|
Chris@0
|
69 # re-enable Subversion for following tests
|
Chris@0
|
70 Setting.delete_all
|
Chris@0
|
71 end
|
Chris@0
|
72
|
Chris@0
|
73 def test_scan_changesets_for_issue_ids
|
Chris@0
|
74 Setting.default_language = 'en'
|
chris@37
|
75 Setting.notified_events = ['issue_added','issue_updated']
|
Chris@0
|
76
|
Chris@0
|
77 # choosing a status to apply to fix issues
|
Chris@0
|
78 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
|
Chris@0
|
79 Setting.commit_fix_done_ratio = "90"
|
Chris@0
|
80 Setting.commit_ref_keywords = 'refs , references, IssueID'
|
Chris@0
|
81 Setting.commit_fix_keywords = 'fixes , closes'
|
Chris@0
|
82 Setting.default_language = 'en'
|
Chris@0
|
83 ActionMailer::Base.deliveries.clear
|
Chris@0
|
84
|
Chris@0
|
85 # make sure issue 1 is not already closed
|
Chris@0
|
86 fixed_issue = Issue.find(1)
|
Chris@0
|
87 assert !fixed_issue.status.is_closed?
|
Chris@0
|
88 old_status = fixed_issue.status
|
Chris@0
|
89
|
Chris@0
|
90 Repository.scan_changesets_for_issue_ids
|
Chris@0
|
91 assert_equal [101, 102], Issue.find(3).changeset_ids
|
Chris@0
|
92
|
Chris@0
|
93 # fixed issues
|
Chris@0
|
94 fixed_issue.reload
|
Chris@0
|
95 assert fixed_issue.status.is_closed?
|
Chris@0
|
96 assert_equal 90, fixed_issue.done_ratio
|
Chris@0
|
97 assert_equal [101], fixed_issue.changeset_ids
|
Chris@0
|
98
|
Chris@0
|
99 # issue change
|
Chris@0
|
100 journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
|
Chris@0
|
101 assert_equal User.find_by_login('dlopper'), journal.user
|
Chris@0
|
102 assert_equal 'Applied in changeset r2.', journal.notes
|
Chris@0
|
103
|
Chris@0
|
104 # 2 email notifications
|
Chris@0
|
105 assert_equal 2, ActionMailer::Base.deliveries.size
|
Chris@0
|
106 mail = ActionMailer::Base.deliveries.first
|
Chris@0
|
107 assert_kind_of TMail::Mail, mail
|
Chris@0
|
108 assert mail.subject.starts_with?("[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
|
Chris@0
|
109 assert mail.body.include?("Status changed from #{old_status} to #{fixed_issue.status}")
|
Chris@0
|
110
|
Chris@0
|
111 # ignoring commits referencing an issue of another project
|
Chris@0
|
112 assert_equal [], Issue.find(4).changesets
|
Chris@0
|
113 end
|
Chris@0
|
114
|
Chris@0
|
115 def test_for_changeset_comments_strip
|
Chris@0
|
116 repository = Repository::Mercurial.create( :project => Project.find( 4 ), :url => '/foo/bar/baz' )
|
Chris@0
|
117 comment = <<-COMMENT
|
Chris@0
|
118 This is a loooooooooooooooooooooooooooong comment
|
Chris@0
|
119
|
Chris@0
|
120
|
Chris@0
|
121 COMMENT
|
Chris@0
|
122 changeset = Changeset.new(
|
Chris@0
|
123 :comments => comment, :commit_date => Time.now, :revision => 0, :scmid => 'f39b7922fb3c',
|
Chris@0
|
124 :committer => 'foo <foo@example.com>', :committed_on => Time.now, :repository => repository )
|
Chris@0
|
125 assert( changeset.save )
|
Chris@0
|
126 assert_not_equal( comment, changeset.comments )
|
Chris@0
|
127 assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments )
|
Chris@0
|
128 end
|
Chris@0
|
129
|
Chris@0
|
130 def test_for_urls_strip
|
Chris@0
|
131 repository = Repository::Cvs.create(:project => Project.find(4), :url => ' :pserver:login:password@host:/path/to/the/repository',
|
Chris@0
|
132 :root_url => 'foo ')
|
Chris@0
|
133 assert repository.save
|
Chris@0
|
134 repository.reload
|
Chris@0
|
135 assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url
|
Chris@0
|
136 assert_equal 'foo', repository.root_url
|
Chris@0
|
137 end
|
Chris@0
|
138
|
Chris@0
|
139 def test_manual_user_mapping
|
Chris@0
|
140 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
|
Chris@0
|
141 c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
|
Chris@0
|
142 assert_nil c.user
|
Chris@0
|
143 @repository.committer_ids = {'foo' => '2'}
|
Chris@0
|
144 assert_equal User.find(2), c.reload.user
|
Chris@0
|
145 # committer is now mapped
|
Chris@0
|
146 c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 101, :comments => 'Another commit by foo.')
|
Chris@0
|
147 assert_equal User.find(2), c.user
|
Chris@0
|
148 end
|
Chris@0
|
149 end
|
Chris@0
|
150
|
Chris@0
|
151 def test_auto_user_mapping_by_username
|
Chris@0
|
152 c = Changeset.create!(:repository => @repository, :committer => 'jsmith', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.')
|
Chris@0
|
153 assert_equal User.find(2), c.user
|
Chris@0
|
154 end
|
Chris@0
|
155
|
Chris@0
|
156 def test_auto_user_mapping_by_email
|
Chris@0
|
157 c = Changeset.create!(:repository => @repository, :committer => 'john <jsmith@somenet.foo>', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.')
|
Chris@0
|
158 assert_equal User.find(2), c.user
|
Chris@0
|
159 end
|
Chris@0
|
160 end
|