annotate .svn/pristine/7e/7e73ff3802954a96975f8bef9c7ea4c0ded85956.svn-base @ 1296:038ba2d95de8 redmine-2.2

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