annotate .svn/pristine/c5/c5babbe46fab862c827420531f4d70904c54b5e3.svn-base @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class RepositoryTest < ActiveSupport::TestCase
Chris@1295 21 fixtures :projects,
Chris@1295 22 :trackers,
Chris@1295 23 :projects_trackers,
Chris@1295 24 :enabled_modules,
Chris@1295 25 :repositories,
Chris@1295 26 :issues,
Chris@1295 27 :issue_statuses,
Chris@1295 28 :issue_categories,
Chris@1295 29 :changesets,
Chris@1295 30 :changes,
Chris@1295 31 :users,
Chris@1295 32 :members,
Chris@1295 33 :member_roles,
Chris@1295 34 :roles,
Chris@1295 35 :enumerations
Chris@1295 36
Chris@1295 37 include Redmine::I18n
Chris@1295 38
Chris@1295 39 def setup
Chris@1295 40 @repository = Project.find(1).repository
Chris@1295 41 end
Chris@1295 42
Chris@1295 43 def test_blank_log_encoding_error_message
Chris@1295 44 set_language_if_valid 'en'
Chris@1295 45 repo = Repository::Bazaar.new(
Chris@1295 46 :project => Project.find(3),
Chris@1295 47 :url => "/test",
Chris@1295 48 :log_encoding => ''
Chris@1295 49 )
Chris@1295 50 assert !repo.save
Chris@1295 51 assert_include "Commit messages encoding can't be blank",
Chris@1295 52 repo.errors.full_messages
Chris@1295 53 end
Chris@1295 54
Chris@1295 55 def test_blank_log_encoding_error_message_fr
Chris@1295 56 set_language_if_valid 'fr'
Chris@1295 57 str = "Encodage des messages de commit doit \xc3\xaatre renseign\xc3\xa9(e)"
Chris@1295 58 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
Chris@1295 59 repo = Repository::Bazaar.new(
Chris@1295 60 :project => Project.find(3),
Chris@1295 61 :url => "/test"
Chris@1295 62 )
Chris@1295 63 assert !repo.save
Chris@1295 64 assert_include str, repo.errors.full_messages
Chris@1295 65 end
Chris@1295 66
Chris@1295 67 def test_create
Chris@1295 68 repository = Repository::Subversion.new(:project => Project.find(3))
Chris@1295 69 assert !repository.save
Chris@1295 70
Chris@1295 71 repository.url = "svn://localhost"
Chris@1295 72 assert repository.save
Chris@1295 73 repository.reload
Chris@1295 74
Chris@1295 75 project = Project.find(3)
Chris@1295 76 assert_equal repository, project.repository
Chris@1295 77 end
Chris@1295 78
Chris@1295 79 def test_first_repository_should_be_set_as_default
Chris@1295 80 repository1 = Repository::Subversion.new(
Chris@1295 81 :project => Project.find(3),
Chris@1295 82 :identifier => 'svn1',
Chris@1295 83 :url => 'file:///svn1'
Chris@1295 84 )
Chris@1295 85 assert repository1.save
Chris@1295 86 assert repository1.is_default?
Chris@1295 87
Chris@1295 88 repository2 = Repository::Subversion.new(
Chris@1295 89 :project => Project.find(3),
Chris@1295 90 :identifier => 'svn2',
Chris@1295 91 :url => 'file:///svn2'
Chris@1295 92 )
Chris@1295 93 assert repository2.save
Chris@1295 94 assert !repository2.is_default?
Chris@1295 95
Chris@1295 96 assert_equal repository1, Project.find(3).repository
Chris@1295 97 assert_equal [repository1, repository2], Project.find(3).repositories.sort
Chris@1295 98 end
Chris@1295 99
Chris@1295 100 def test_identifier_should_accept_letters_digits_dashes_and_underscores
Chris@1295 101 r = Repository::Subversion.new(
Chris@1295 102 :project_id => 3,
Chris@1295 103 :identifier => 'svn-123_45',
Chris@1295 104 :url => 'file:///svn'
Chris@1295 105 )
Chris@1295 106 assert r.save
Chris@1295 107 end
Chris@1295 108
Chris@1295 109 def test_identifier_should_not_be_frozen_for_a_new_repository
Chris@1295 110 assert_equal false, Repository.new.identifier_frozen?
Chris@1295 111 end
Chris@1295 112
Chris@1295 113 def test_identifier_should_not_be_frozen_for_a_saved_repository_with_blank_identifier
Chris@1295 114 Repository.update_all(["identifier = ''"], "id = 10")
Chris@1295 115
Chris@1295 116 assert_equal false, Repository.find(10).identifier_frozen?
Chris@1295 117 end
Chris@1295 118
Chris@1295 119 def test_identifier_should_be_frozen_for_a_saved_repository_with_valid_identifier
Chris@1295 120 Repository.update_all(["identifier = 'abc123'"], "id = 10")
Chris@1295 121
Chris@1295 122 assert_equal true, Repository.find(10).identifier_frozen?
Chris@1295 123 end
Chris@1295 124
Chris@1295 125 def test_identifier_should_not_accept_change_if_frozen
Chris@1295 126 r = Repository.new(:identifier => 'foo')
Chris@1295 127 r.stubs(:identifier_frozen?).returns(true)
Chris@1295 128
Chris@1295 129 r.identifier = 'bar'
Chris@1295 130 assert_equal 'foo', r.identifier
Chris@1295 131 end
Chris@1295 132
Chris@1295 133 def test_identifier_should_accept_change_if_not_frozen
Chris@1295 134 r = Repository.new(:identifier => 'foo')
Chris@1295 135 r.stubs(:identifier_frozen?).returns(false)
Chris@1295 136
Chris@1295 137 r.identifier = 'bar'
Chris@1295 138 assert_equal 'bar', r.identifier
Chris@1295 139 end
Chris@1295 140
Chris@1295 141 def test_destroy
Chris@1295 142 repository = Repository.find(10)
Chris@1295 143 changesets = repository.changesets.count
Chris@1295 144 changes = repository.filechanges.count
Chris@1295 145
Chris@1295 146 assert_difference 'Changeset.count', -changesets do
Chris@1295 147 assert_difference 'Change.count', -changes do
Chris@1295 148 Repository.find(10).destroy
Chris@1295 149 end
Chris@1295 150 end
Chris@1295 151 end
Chris@1295 152
Chris@1295 153 def test_destroy_should_delete_parents_associations
Chris@1295 154 changeset = Changeset.find(102)
Chris@1295 155 changeset.parents = Changeset.find_all_by_id([100, 101])
Chris@1295 156
Chris@1295 157 assert_difference 'Changeset.connection.select_all("select * from changeset_parents").size', -2 do
Chris@1295 158 Repository.find(10).destroy
Chris@1295 159 end
Chris@1295 160 end
Chris@1295 161
Chris@1295 162 def test_destroy_should_delete_issues_associations
Chris@1295 163 changeset = Changeset.find(102)
Chris@1295 164 changeset.issues = Issue.find_all_by_id([1, 2])
Chris@1295 165
Chris@1295 166 assert_difference 'Changeset.connection.select_all("select * from changesets_issues").size', -2 do
Chris@1295 167 Repository.find(10).destroy
Chris@1295 168 end
Chris@1295 169 end
Chris@1295 170
Chris@1295 171 def test_should_not_create_with_disabled_scm
Chris@1295 172 # disable Subversion
Chris@1295 173 with_settings :enabled_scm => ['Darcs', 'Git'] do
Chris@1295 174 repository = Repository::Subversion.new(
Chris@1295 175 :project => Project.find(3), :url => "svn://localhost")
Chris@1295 176 assert !repository.save
Chris@1295 177 assert_include I18n.translate('activerecord.errors.messages.invalid'),
Chris@1295 178 repository.errors[:type]
Chris@1295 179 end
Chris@1295 180 end
Chris@1295 181
Chris@1295 182 def test_scan_changesets_for_issue_ids
Chris@1295 183 Setting.default_language = 'en'
Chris@1295 184
Chris@1295 185 # choosing a status to apply to fix issues
Chris@1295 186 Setting.commit_fix_status_id = IssueStatus.find(
Chris@1295 187 :first,
Chris@1295 188 :conditions => ["is_closed = ?", true]).id
Chris@1295 189 Setting.commit_fix_done_ratio = "90"
Chris@1295 190 Setting.commit_ref_keywords = 'refs , references, IssueID'
Chris@1295 191 Setting.commit_fix_keywords = 'fixes , closes'
Chris@1295 192 Setting.default_language = 'en'
Chris@1295 193 ActionMailer::Base.deliveries.clear
Chris@1295 194
Chris@1295 195 # make sure issue 1 is not already closed
Chris@1295 196 fixed_issue = Issue.find(1)
Chris@1295 197 assert !fixed_issue.status.is_closed?
Chris@1295 198 old_status = fixed_issue.status
Chris@1295 199
Chris@1295 200 with_settings :notified_events => %w(issue_added issue_updated) do
Chris@1295 201 Repository.scan_changesets_for_issue_ids
Chris@1295 202 end
Chris@1295 203 assert_equal [101, 102], Issue.find(3).changeset_ids
Chris@1295 204
Chris@1295 205 # fixed issues
Chris@1295 206 fixed_issue.reload
Chris@1295 207 assert fixed_issue.status.is_closed?
Chris@1295 208 assert_equal 90, fixed_issue.done_ratio
Chris@1295 209 assert_equal [101], fixed_issue.changeset_ids
Chris@1295 210
Chris@1295 211 # issue change
Chris@1295 212 journal = fixed_issue.journals.reorder('created_on desc').first
Chris@1295 213 assert_equal User.find_by_login('dlopper'), journal.user
Chris@1295 214 assert_equal 'Applied in changeset r2.', journal.notes
Chris@1295 215
Chris@1295 216 # 2 email notifications
Chris@1295 217 assert_equal 2, ActionMailer::Base.deliveries.size
Chris@1295 218 mail = ActionMailer::Base.deliveries.first
Chris@1295 219 assert_not_nil mail
Chris@1295 220 assert mail.subject.starts_with?(
Chris@1295 221 "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
Chris@1295 222 assert_mail_body_match(
Chris@1295 223 "Status changed from #{old_status} to #{fixed_issue.status}", mail)
Chris@1295 224
Chris@1295 225 # ignoring commits referencing an issue of another project
Chris@1295 226 assert_equal [], Issue.find(4).changesets
Chris@1295 227 end
Chris@1295 228
Chris@1295 229 def test_for_changeset_comments_strip
Chris@1295 230 repository = Repository::Mercurial.create(
Chris@1295 231 :project => Project.find( 4 ),
Chris@1295 232 :url => '/foo/bar/baz' )
Chris@1295 233 comment = <<-COMMENT
Chris@1295 234 This is a loooooooooooooooooooooooooooong comment
Chris@1295 235
Chris@1295 236
Chris@1295 237 COMMENT
Chris@1295 238 changeset = Changeset.new(
Chris@1295 239 :comments => comment, :commit_date => Time.now,
Chris@1295 240 :revision => 0, :scmid => 'f39b7922fb3c',
Chris@1295 241 :committer => 'foo <foo@example.com>',
Chris@1295 242 :committed_on => Time.now, :repository => repository )
Chris@1295 243 assert( changeset.save )
Chris@1295 244 assert_not_equal( comment, changeset.comments )
Chris@1295 245 assert_equal( 'This is a loooooooooooooooooooooooooooong comment',
Chris@1295 246 changeset.comments )
Chris@1295 247 end
Chris@1295 248
Chris@1295 249 def test_for_urls_strip_cvs
Chris@1295 250 repository = Repository::Cvs.create(
Chris@1295 251 :project => Project.find(4),
Chris@1295 252 :url => ' :pserver:login:password@host:/path/to/the/repository',
Chris@1295 253 :root_url => 'foo ',
Chris@1295 254 :log_encoding => 'UTF-8')
Chris@1295 255 assert repository.save
Chris@1295 256 repository.reload
Chris@1295 257 assert_equal ':pserver:login:password@host:/path/to/the/repository',
Chris@1295 258 repository.url
Chris@1295 259 assert_equal 'foo', repository.root_url
Chris@1295 260 end
Chris@1295 261
Chris@1295 262 def test_for_urls_strip_subversion
Chris@1295 263 repository = Repository::Subversion.create(
Chris@1295 264 :project => Project.find(4),
Chris@1295 265 :url => ' file:///dummy ')
Chris@1295 266 assert repository.save
Chris@1295 267 repository.reload
Chris@1295 268 assert_equal 'file:///dummy', repository.url
Chris@1295 269 end
Chris@1295 270
Chris@1295 271 def test_for_urls_strip_git
Chris@1295 272 repository = Repository::Git.create(
Chris@1295 273 :project => Project.find(4),
Chris@1295 274 :url => ' c:\dummy ')
Chris@1295 275 assert repository.save
Chris@1295 276 repository.reload
Chris@1295 277 assert_equal 'c:\dummy', repository.url
Chris@1295 278 end
Chris@1295 279
Chris@1295 280 def test_manual_user_mapping
Chris@1295 281 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
Chris@1295 282 c = Changeset.create!(
Chris@1295 283 :repository => @repository,
Chris@1295 284 :committer => 'foo',
Chris@1295 285 :committed_on => Time.now,
Chris@1295 286 :revision => 100,
Chris@1295 287 :comments => 'Committed by foo.'
Chris@1295 288 )
Chris@1295 289 assert_nil c.user
Chris@1295 290 @repository.committer_ids = {'foo' => '2'}
Chris@1295 291 assert_equal User.find(2), c.reload.user
Chris@1295 292 # committer is now mapped
Chris@1295 293 c = Changeset.create!(
Chris@1295 294 :repository => @repository,
Chris@1295 295 :committer => 'foo',
Chris@1295 296 :committed_on => Time.now,
Chris@1295 297 :revision => 101,
Chris@1295 298 :comments => 'Another commit by foo.'
Chris@1295 299 )
Chris@1295 300 assert_equal User.find(2), c.user
Chris@1295 301 end
Chris@1295 302 end
Chris@1295 303
Chris@1295 304 def test_auto_user_mapping_by_username
Chris@1295 305 c = Changeset.create!(
Chris@1295 306 :repository => @repository,
Chris@1295 307 :committer => 'jsmith',
Chris@1295 308 :committed_on => Time.now,
Chris@1295 309 :revision => 100,
Chris@1295 310 :comments => 'Committed by john.'
Chris@1295 311 )
Chris@1295 312 assert_equal User.find(2), c.user
Chris@1295 313 end
Chris@1295 314
Chris@1295 315 def test_auto_user_mapping_by_email
Chris@1295 316 c = Changeset.create!(
Chris@1295 317 :repository => @repository,
Chris@1295 318 :committer => 'john <jsmith@somenet.foo>',
Chris@1295 319 :committed_on => Time.now,
Chris@1295 320 :revision => 100,
Chris@1295 321 :comments => 'Committed by john.'
Chris@1295 322 )
Chris@1295 323 assert_equal User.find(2), c.user
Chris@1295 324 end
Chris@1295 325
Chris@1295 326 def test_filesystem_avaialbe
Chris@1295 327 klass = Repository::Filesystem
Chris@1295 328 assert klass.scm_adapter_class
Chris@1295 329 assert_equal true, klass.scm_available
Chris@1295 330 end
Chris@1295 331
Chris@1295 332 def test_merge_extra_info
Chris@1295 333 repo = Repository::Subversion.new(:project => Project.find(3))
Chris@1295 334 assert !repo.save
Chris@1295 335 repo.url = "svn://localhost"
Chris@1295 336 assert repo.save
Chris@1295 337 repo.reload
Chris@1295 338 project = Project.find(3)
Chris@1295 339 assert_equal repo, project.repository
Chris@1295 340 assert_nil repo.extra_info
Chris@1295 341 h1 = {"test_1" => {"test_11" => "test_value_11"}}
Chris@1295 342 repo.merge_extra_info(h1)
Chris@1295 343 assert_equal h1, repo.extra_info
Chris@1295 344 h2 = {"test_2" => {
Chris@1295 345 "test_21" => "test_value_21",
Chris@1295 346 "test_22" => "test_value_22",
Chris@1295 347 }}
Chris@1295 348 repo.merge_extra_info(h2)
Chris@1295 349 assert_equal (h = {"test_11" => "test_value_11"}),
Chris@1295 350 repo.extra_info["test_1"]
Chris@1295 351 assert_equal "test_value_21",
Chris@1295 352 repo.extra_info["test_2"]["test_21"]
Chris@1295 353 h3 = {"test_2" => {
Chris@1295 354 "test_23" => "test_value_23",
Chris@1295 355 "test_24" => "test_value_24",
Chris@1295 356 }}
Chris@1295 357 repo.merge_extra_info(h3)
Chris@1295 358 assert_equal (h = {"test_11" => "test_value_11"}),
Chris@1295 359 repo.extra_info["test_1"]
Chris@1295 360 assert_nil repo.extra_info["test_2"]["test_21"]
Chris@1295 361 assert_equal "test_value_23",
Chris@1295 362 repo.extra_info["test_2"]["test_23"]
Chris@1295 363 end
Chris@1295 364
Chris@1295 365 def test_sort_should_not_raise_an_error_with_nil_identifiers
Chris@1295 366 r1 = Repository.new
Chris@1295 367 r2 = Repository.new
Chris@1295 368
Chris@1295 369 assert_nothing_raised do
Chris@1295 370 [r1, r2].sort
Chris@1295 371 end
Chris@1295 372 end
Chris@1295 373 end