annotate test/unit/repository_test.rb @ 1169:492ff72268e3 bug_521

Close obsolete branch bug_521
author Chris Cannam
date Thu, 18 Oct 2012 10:42:48 +0100
parents cbb26bc654de
children 433d4f72a19b
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 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@441 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@441 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@119 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@119 24 :enabled_modules,
Chris@0 25 :repositories,
Chris@0 26 :issues,
Chris@0 27 :issue_statuses,
Chris@119 28 :issue_categories,
Chris@0 29 :changesets,
Chris@0 30 :changes,
Chris@0 31 :users,
Chris@119 32 :members,
Chris@119 33 :member_roles,
Chris@119 34 :roles,
Chris@0 35 :enumerations
Chris@441 36
Chris@0 37 def setup
Chris@0 38 @repository = Project.find(1).repository
Chris@0 39 end
Chris@441 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@441 44
Chris@0 45 repository.url = "svn://localhost"
Chris@0 46 assert repository.save
Chris@0 47 repository.reload
Chris@441 48
Chris@0 49 project = Project.find(3)
Chris@0 50 assert_equal repository, project.repository
Chris@0 51 end
Chris@441 52
Chris@0 53 def test_destroy
Chris@0 54 changesets = Changeset.count(:all, :conditions => "repository_id = 10")
Chris@441 55 changes = Change.count(:all, :conditions => "repository_id = 10",
Chris@441 56 :include => :changeset)
Chris@0 57 assert_difference 'Changeset.count', -changesets do
Chris@0 58 assert_difference 'Change.count', -changes do
Chris@0 59 Repository.find(10).destroy
Chris@0 60 end
Chris@0 61 end
Chris@0 62 end
Chris@441 63
Chris@0 64 def test_should_not_create_with_disabled_scm
Chris@0 65 # disable Subversion
Chris@128 66 with_settings :enabled_scm => ['Darcs', 'Git'] do
Chris@441 67 repository = Repository::Subversion.new(
Chris@441 68 :project => Project.find(3), :url => "svn://localhost")
Chris@128 69 assert !repository.save
Chris@441 70 assert_equal I18n.translate('activerecord.errors.messages.invalid'),
Chris@441 71 repository.errors.on(:type)
Chris@128 72 end
Chris@0 73 end
Chris@441 74
Chris@0 75 def test_scan_changesets_for_issue_ids
Chris@0 76 Setting.default_language = 'en'
chris@37 77 Setting.notified_events = ['issue_added','issue_updated']
Chris@441 78
Chris@0 79 # choosing a status to apply to fix issues
Chris@441 80 Setting.commit_fix_status_id = IssueStatus.find(
Chris@441 81 :first,
Chris@441 82 :conditions => ["is_closed = ?", true]).id
Chris@0 83 Setting.commit_fix_done_ratio = "90"
Chris@0 84 Setting.commit_ref_keywords = 'refs , references, IssueID'
Chris@0 85 Setting.commit_fix_keywords = 'fixes , closes'
Chris@0 86 Setting.default_language = 'en'
Chris@0 87 ActionMailer::Base.deliveries.clear
Chris@441 88
Chris@0 89 # make sure issue 1 is not already closed
Chris@0 90 fixed_issue = Issue.find(1)
Chris@0 91 assert !fixed_issue.status.is_closed?
Chris@0 92 old_status = fixed_issue.status
Chris@441 93
Chris@0 94 Repository.scan_changesets_for_issue_ids
Chris@0 95 assert_equal [101, 102], Issue.find(3).changeset_ids
Chris@441 96
Chris@0 97 # fixed issues
Chris@0 98 fixed_issue.reload
Chris@0 99 assert fixed_issue.status.is_closed?
Chris@0 100 assert_equal 90, fixed_issue.done_ratio
Chris@0 101 assert_equal [101], fixed_issue.changeset_ids
Chris@441 102
Chris@0 103 # issue change
Chris@0 104 journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
Chris@0 105 assert_equal User.find_by_login('dlopper'), journal.user
Chris@0 106 assert_equal 'Applied in changeset r2.', journal.notes
Chris@441 107
Chris@0 108 # 2 email notifications
Chris@0 109 assert_equal 2, ActionMailer::Base.deliveries.size
Chris@0 110 mail = ActionMailer::Base.deliveries.first
Chris@0 111 assert_kind_of TMail::Mail, mail
Chris@441 112 assert mail.subject.starts_with?(
Chris@441 113 "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
Chris@441 114 assert mail.body.include?(
Chris@441 115 "Status changed from #{old_status} to #{fixed_issue.status}")
Chris@441 116
Chris@0 117 # ignoring commits referencing an issue of another project
Chris@0 118 assert_equal [], Issue.find(4).changesets
Chris@0 119 end
Chris@441 120
Chris@0 121 def test_for_changeset_comments_strip
Chris@441 122 repository = Repository::Mercurial.create(
Chris@441 123 :project => Project.find( 4 ),
Chris@441 124 :url => '/foo/bar/baz' )
Chris@0 125 comment = <<-COMMENT
Chris@0 126 This is a loooooooooooooooooooooooooooong comment
Chris@0 127
Chris@0 128
Chris@0 129 COMMENT
Chris@0 130 changeset = Changeset.new(
Chris@441 131 :comments => comment, :commit_date => Time.now,
Chris@441 132 :revision => 0, :scmid => 'f39b7922fb3c',
Chris@441 133 :committer => 'foo <foo@example.com>',
Chris@441 134 :committed_on => Time.now, :repository => repository )
Chris@0 135 assert( changeset.save )
Chris@0 136 assert_not_equal( comment, changeset.comments )
Chris@441 137 assert_equal( 'This is a loooooooooooooooooooooooooooong comment',
Chris@441 138 changeset.comments )
Chris@0 139 end
Chris@245 140
Chris@909 141 def test_for_urls_strip_cvs
Chris@245 142 repository = Repository::Cvs.create(
Chris@245 143 :project => Project.find(4),
Chris@245 144 :url => ' :pserver:login:password@host:/path/to/the/repository',
Chris@245 145 :root_url => 'foo ',
Chris@245 146 :log_encoding => 'UTF-8')
Chris@0 147 assert repository.save
Chris@0 148 repository.reload
Chris@441 149 assert_equal ':pserver:login:password@host:/path/to/the/repository',
Chris@441 150 repository.url
Chris@0 151 assert_equal 'foo', repository.root_url
Chris@0 152 end
Chris@245 153
Chris@909 154 def test_for_urls_strip_subversion
Chris@909 155 repository = Repository::Subversion.create(
Chris@909 156 :project => Project.find(4),
Chris@909 157 :url => ' file:///dummy ')
Chris@909 158 assert repository.save
Chris@909 159 repository.reload
Chris@909 160 assert_equal 'file:///dummy', repository.url
Chris@909 161 end
Chris@909 162
Chris@909 163 def test_for_urls_strip_git
Chris@909 164 repository = Repository::Git.create(
Chris@909 165 :project => Project.find(4),
Chris@909 166 :url => ' c:\dummy ')
Chris@909 167 assert repository.save
Chris@909 168 repository.reload
Chris@909 169 assert_equal 'c:\dummy', repository.url
Chris@909 170 end
Chris@909 171
Chris@0 172 def test_manual_user_mapping
Chris@0 173 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
Chris@441 174 c = Changeset.create!(
Chris@441 175 :repository => @repository,
Chris@441 176 :committer => 'foo',
Chris@441 177 :committed_on => Time.now,
Chris@441 178 :revision => 100,
Chris@441 179 :comments => 'Committed by foo.'
Chris@441 180 )
Chris@0 181 assert_nil c.user
Chris@0 182 @repository.committer_ids = {'foo' => '2'}
Chris@0 183 assert_equal User.find(2), c.reload.user
Chris@0 184 # committer is now mapped
Chris@441 185 c = Changeset.create!(
Chris@441 186 :repository => @repository,
Chris@441 187 :committer => 'foo',
Chris@441 188 :committed_on => Time.now,
Chris@441 189 :revision => 101,
Chris@441 190 :comments => 'Another commit by foo.'
Chris@441 191 )
Chris@0 192 assert_equal User.find(2), c.user
Chris@0 193 end
Chris@0 194 end
Chris@441 195
Chris@0 196 def test_auto_user_mapping_by_username
Chris@441 197 c = Changeset.create!(
Chris@441 198 :repository => @repository,
Chris@441 199 :committer => 'jsmith',
Chris@441 200 :committed_on => Time.now,
Chris@441 201 :revision => 100,
Chris@441 202 :comments => 'Committed by john.'
Chris@441 203 )
Chris@0 204 assert_equal User.find(2), c.user
Chris@0 205 end
Chris@441 206
Chris@0 207 def test_auto_user_mapping_by_email
Chris@441 208 c = Changeset.create!(
Chris@441 209 :repository => @repository,
Chris@441 210 :committer => 'john <jsmith@somenet.foo>',
Chris@441 211 :committed_on => Time.now,
Chris@441 212 :revision => 100,
Chris@441 213 :comments => 'Committed by john.'
Chris@441 214 )
Chris@0 215 assert_equal User.find(2), c.user
Chris@0 216 end
Chris@441 217
Chris@441 218 def test_filesystem_avaialbe
Chris@441 219 klass = Repository::Filesystem
Chris@441 220 assert klass.scm_adapter_class
Chris@441 221 assert_equal true, klass.scm_available
Chris@441 222 end
Chris@441 223
Chris@441 224 def test_merge_extra_info
Chris@441 225 repo = Repository::Subversion.new(:project => Project.find(3))
Chris@441 226 assert !repo.save
Chris@441 227 repo.url = "svn://localhost"
Chris@441 228 assert repo.save
Chris@441 229 repo.reload
Chris@441 230 project = Project.find(3)
Chris@441 231 assert_equal repo, project.repository
Chris@441 232 assert_nil repo.extra_info
Chris@441 233 h1 = {"test_1" => {"test_11" => "test_value_11"}}
Chris@441 234 repo.merge_extra_info(h1)
Chris@441 235 assert_equal h1, repo.extra_info
Chris@441 236 h2 = {"test_2" => {
Chris@441 237 "test_21" => "test_value_21",
Chris@441 238 "test_22" => "test_value_22",
Chris@441 239 }}
Chris@441 240 repo.merge_extra_info(h2)
Chris@441 241 assert_equal (h = {"test_11" => "test_value_11"}),
Chris@441 242 repo.extra_info["test_1"]
Chris@441 243 assert_equal "test_value_21",
Chris@441 244 repo.extra_info["test_2"]["test_21"]
Chris@441 245 h3 = {"test_2" => {
Chris@441 246 "test_23" => "test_value_23",
Chris@441 247 "test_24" => "test_value_24",
Chris@441 248 }}
Chris@441 249 repo.merge_extra_info(h3)
Chris@441 250 assert_equal (h = {"test_11" => "test_value_11"}),
Chris@441 251 repo.extra_info["test_1"]
Chris@441 252 assert_nil repo.extra_info["test_2"]["test_21"]
Chris@441 253 assert_equal "test_value_23",
Chris@441 254 repo.extra_info["test_2"]["test_23"]
Chris@441 255 end
Chris@0 256 end