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