annotate .svn/pristine/4b/4b0ab7a9a0cc26a2efc7c3d1e437ca0de83aa262.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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