annotate .svn/pristine/f4/f45cadd45e22c8df0a53045d3c2f398d9f064ea9.svn-base @ 1464:261b3d9a4903 redmine-2.4

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