annotate .svn/pristine/ec/eca338e91ed55d8ddb08b679547cdd8ac30e480a.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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