To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 45 / 45db780cec4e0c72778412b47b7cf78b370991c8.svn-base @ 1298:4f746d8966dd
History | View | Annotate | Download (17.1 KB)
| 1 |
# encoding: utf-8 |
|---|---|
| 2 |
# |
| 3 |
# Redmine - project management software |
| 4 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or |
| 7 |
# modify it under the terms of the GNU General Public License |
| 8 |
# as published by the Free Software Foundation; either version 2 |
| 9 |
# of the License, or (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program; if not, write to the Free Software |
| 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 |
|
| 20 |
require File.expand_path('../../test_helper', __FILE__)
|
| 21 |
|
| 22 |
class ChangesetTest < ActiveSupport::TestCase |
| 23 |
fixtures :projects, :repositories, |
| 24 |
:issues, :issue_statuses, :issue_categories, |
| 25 |
:changesets, :changes, |
| 26 |
:enumerations, |
| 27 |
:custom_fields, :custom_values, |
| 28 |
:users, :members, :member_roles, :trackers, |
| 29 |
:enabled_modules, :roles |
| 30 |
|
| 31 |
def test_ref_keywords_any |
| 32 |
ActionMailer::Base.deliveries.clear |
| 33 |
Setting.commit_fix_status_id = IssueStatus.find( |
| 34 |
:first, :conditions => ["is_closed = ?", true]).id |
| 35 |
Setting.commit_fix_done_ratio = '90' |
| 36 |
Setting.commit_ref_keywords = '*' |
| 37 |
Setting.commit_fix_keywords = 'fixes , closes' |
| 38 |
|
| 39 |
c = Changeset.new(:repository => Project.find(1).repository, |
| 40 |
:committed_on => Time.now, |
| 41 |
:comments => 'New commit (#2). Fixes #1', |
| 42 |
:revision => '12345') |
| 43 |
assert c.save |
| 44 |
assert_equal [1, 2], c.issue_ids.sort |
| 45 |
fixed = Issue.find(1) |
| 46 |
assert fixed.closed? |
| 47 |
assert_equal 90, fixed.done_ratio |
| 48 |
assert_equal 1, ActionMailer::Base.deliveries.size |
| 49 |
end |
| 50 |
|
| 51 |
def test_ref_keywords |
| 52 |
Setting.commit_ref_keywords = 'refs' |
| 53 |
Setting.commit_fix_keywords = '' |
| 54 |
c = Changeset.new(:repository => Project.find(1).repository, |
| 55 |
:committed_on => Time.now, |
| 56 |
:comments => 'Ignores #2. Refs #1', |
| 57 |
:revision => '12345') |
| 58 |
assert c.save |
| 59 |
assert_equal [1], c.issue_ids.sort |
| 60 |
end |
| 61 |
|
| 62 |
def test_ref_keywords_any_only |
| 63 |
Setting.commit_ref_keywords = '*' |
| 64 |
Setting.commit_fix_keywords = '' |
| 65 |
c = Changeset.new(:repository => Project.find(1).repository, |
| 66 |
:committed_on => Time.now, |
| 67 |
:comments => 'Ignores #2. Refs #1', |
| 68 |
:revision => '12345') |
| 69 |
assert c.save |
| 70 |
assert_equal [1, 2], c.issue_ids.sort |
| 71 |
end |
| 72 |
|
| 73 |
def test_ref_keywords_any_with_timelog |
| 74 |
Setting.commit_ref_keywords = '*' |
| 75 |
Setting.commit_logtime_enabled = '1' |
| 76 |
|
| 77 |
{
|
| 78 |
'2' => 2.0, |
| 79 |
'2h' => 2.0, |
| 80 |
'2hours' => 2.0, |
| 81 |
'15m' => 0.25, |
| 82 |
'15min' => 0.25, |
| 83 |
'3h15' => 3.25, |
| 84 |
'3h15m' => 3.25, |
| 85 |
'3h15min' => 3.25, |
| 86 |
'3:15' => 3.25, |
| 87 |
'3.25' => 3.25, |
| 88 |
'3.25h' => 3.25, |
| 89 |
'3,25' => 3.25, |
| 90 |
'3,25h' => 3.25, |
| 91 |
}.each do |syntax, expected_hours| |
| 92 |
c = Changeset.new(:repository => Project.find(1).repository, |
| 93 |
:committed_on => 24.hours.ago, |
| 94 |
:comments => "Worked on this issue #1 @#{syntax}",
|
| 95 |
:revision => '520', |
| 96 |
:user => User.find(2)) |
| 97 |
assert_difference 'TimeEntry.count' do |
| 98 |
c.scan_comment_for_issue_ids |
| 99 |
end |
| 100 |
assert_equal [1], c.issue_ids.sort |
| 101 |
|
| 102 |
time = TimeEntry.first(:order => 'id desc') |
| 103 |
assert_equal 1, time.issue_id |
| 104 |
assert_equal 1, time.project_id |
| 105 |
assert_equal 2, time.user_id |
| 106 |
assert_equal expected_hours, time.hours, |
| 107 |
"@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
|
| 108 |
assert_equal Date.yesterday, time.spent_on |
| 109 |
assert time.activity.is_default? |
| 110 |
assert time.comments.include?('r520'),
|
| 111 |
"r520 was expected in time_entry comments: #{time.comments}"
|
| 112 |
end |
| 113 |
end |
| 114 |
|
| 115 |
def test_ref_keywords_closing_with_timelog |
| 116 |
Setting.commit_fix_status_id = IssueStatus.find( |
| 117 |
:first, :conditions => ["is_closed = ?", true]).id |
| 118 |
Setting.commit_ref_keywords = '*' |
| 119 |
Setting.commit_fix_keywords = 'fixes , closes' |
| 120 |
Setting.commit_logtime_enabled = '1' |
| 121 |
|
| 122 |
c = Changeset.new(:repository => Project.find(1).repository, |
| 123 |
:committed_on => Time.now, |
| 124 |
:comments => 'This is a comment. Fixes #1 @4.5, #2 @1', |
| 125 |
:user => User.find(2)) |
| 126 |
assert_difference 'TimeEntry.count', 2 do |
| 127 |
c.scan_comment_for_issue_ids |
| 128 |
end |
| 129 |
|
| 130 |
assert_equal [1, 2], c.issue_ids.sort |
| 131 |
assert Issue.find(1).closed? |
| 132 |
assert Issue.find(2).closed? |
| 133 |
|
| 134 |
times = TimeEntry.all(:order => 'id desc', :limit => 2) |
| 135 |
assert_equal [1, 2], times.collect(&:issue_id).sort |
| 136 |
end |
| 137 |
|
| 138 |
def test_ref_keywords_any_line_start |
| 139 |
Setting.commit_ref_keywords = '*' |
| 140 |
c = Changeset.new(:repository => Project.find(1).repository, |
| 141 |
:committed_on => Time.now, |
| 142 |
:comments => '#1 is the reason of this commit', |
| 143 |
:revision => '12345') |
| 144 |
assert c.save |
| 145 |
assert_equal [1], c.issue_ids.sort |
| 146 |
end |
| 147 |
|
| 148 |
def test_ref_keywords_allow_brackets_around_a_issue_number |
| 149 |
Setting.commit_ref_keywords = '*' |
| 150 |
c = Changeset.new(:repository => Project.find(1).repository, |
| 151 |
:committed_on => Time.now, |
| 152 |
:comments => '[#1] Worked on this issue', |
| 153 |
:revision => '12345') |
| 154 |
assert c.save |
| 155 |
assert_equal [1], c.issue_ids.sort |
| 156 |
end |
| 157 |
|
| 158 |
def test_ref_keywords_allow_brackets_around_multiple_issue_numbers |
| 159 |
Setting.commit_ref_keywords = '*' |
| 160 |
c = Changeset.new(:repository => Project.find(1).repository, |
| 161 |
:committed_on => Time.now, |
| 162 |
:comments => '[#1 #2, #3] Worked on these', |
| 163 |
:revision => '12345') |
| 164 |
assert c.save |
| 165 |
assert_equal [1,2,3], c.issue_ids.sort |
| 166 |
end |
| 167 |
|
| 168 |
def test_commit_referencing_a_subproject_issue |
| 169 |
c = Changeset.new(:repository => Project.find(1).repository, |
| 170 |
:committed_on => Time.now, |
| 171 |
:comments => 'refs #5, a subproject issue', |
| 172 |
:revision => '12345') |
| 173 |
assert c.save |
| 174 |
assert_equal [5], c.issue_ids.sort |
| 175 |
assert c.issues.first.project != c.project |
| 176 |
end |
| 177 |
|
| 178 |
def test_commit_closing_a_subproject_issue |
| 179 |
with_settings :commit_fix_status_id => 5, :commit_fix_keywords => 'closes', |
| 180 |
:default_language => 'en' do |
| 181 |
issue = Issue.find(5) |
| 182 |
assert !issue.closed? |
| 183 |
assert_difference 'Journal.count' do |
| 184 |
c = Changeset.new(:repository => Project.find(1).repository, |
| 185 |
:committed_on => Time.now, |
| 186 |
:comments => 'closes #5, a subproject issue', |
| 187 |
:revision => '12345') |
| 188 |
assert c.save |
| 189 |
end |
| 190 |
assert issue.reload.closed? |
| 191 |
journal = Journal.first(:order => 'id DESC') |
| 192 |
assert_equal issue, journal.issue |
| 193 |
assert_include "Applied in changeset ecookbook:r12345.", journal.notes |
| 194 |
end |
| 195 |
end |
| 196 |
|
| 197 |
def test_commit_referencing_a_parent_project_issue |
| 198 |
# repository of child project |
| 199 |
r = Repository::Subversion.create!( |
| 200 |
:project => Project.find(3), |
| 201 |
:url => 'svn://localhost/test') |
| 202 |
c = Changeset.new(:repository => r, |
| 203 |
:committed_on => Time.now, |
| 204 |
:comments => 'refs #2, an issue of a parent project', |
| 205 |
:revision => '12345') |
| 206 |
assert c.save |
| 207 |
assert_equal [2], c.issue_ids.sort |
| 208 |
assert c.issues.first.project != c.project |
| 209 |
end |
| 210 |
|
| 211 |
def test_commit_referencing_a_project_with_commit_cross_project_ref_disabled |
| 212 |
r = Repository::Subversion.create!( |
| 213 |
:project => Project.find(3), |
| 214 |
:url => 'svn://localhost/test') |
| 215 |
|
| 216 |
with_settings :commit_cross_project_ref => '0' do |
| 217 |
c = Changeset.new(:repository => r, |
| 218 |
:committed_on => Time.now, |
| 219 |
:comments => 'refs #4, an issue of a different project', |
| 220 |
:revision => '12345') |
| 221 |
assert c.save |
| 222 |
assert_equal [], c.issue_ids |
| 223 |
end |
| 224 |
end |
| 225 |
|
| 226 |
def test_commit_referencing_a_project_with_commit_cross_project_ref_enabled |
| 227 |
r = Repository::Subversion.create!( |
| 228 |
:project => Project.find(3), |
| 229 |
:url => 'svn://localhost/test') |
| 230 |
|
| 231 |
with_settings :commit_cross_project_ref => '1' do |
| 232 |
c = Changeset.new(:repository => r, |
| 233 |
:committed_on => Time.now, |
| 234 |
:comments => 'refs #4, an issue of a different project', |
| 235 |
:revision => '12345') |
| 236 |
assert c.save |
| 237 |
assert_equal [4], c.issue_ids |
| 238 |
end |
| 239 |
end |
| 240 |
|
| 241 |
def test_text_tag_revision |
| 242 |
c = Changeset.new(:revision => '520') |
| 243 |
assert_equal 'r520', c.text_tag |
| 244 |
end |
| 245 |
|
| 246 |
def test_text_tag_revision_with_same_project |
| 247 |
c = Changeset.new(:revision => '520', :repository => Project.find(1).repository) |
| 248 |
assert_equal 'r520', c.text_tag(Project.find(1)) |
| 249 |
end |
| 250 |
|
| 251 |
def test_text_tag_revision_with_different_project |
| 252 |
c = Changeset.new(:revision => '520', :repository => Project.find(1).repository) |
| 253 |
assert_equal 'ecookbook:r520', c.text_tag(Project.find(2)) |
| 254 |
end |
| 255 |
|
| 256 |
def test_text_tag_revision_with_repository_identifier |
| 257 |
r = Repository::Subversion.create!( |
| 258 |
:project_id => 1, |
| 259 |
:url => 'svn://localhost/test', |
| 260 |
:identifier => 'documents') |
| 261 |
|
| 262 |
c = Changeset.new(:revision => '520', :repository => r) |
| 263 |
assert_equal 'documents|r520', c.text_tag |
| 264 |
assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2)) |
| 265 |
end |
| 266 |
|
| 267 |
def test_text_tag_hash |
| 268 |
c = Changeset.new( |
| 269 |
:scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', |
| 270 |
:revision => '7234cb2750b63f47bff735edc50a1c0a433c2518') |
| 271 |
assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag |
| 272 |
end |
| 273 |
|
| 274 |
def test_text_tag_hash_with_same_project |
| 275 |
c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository) |
| 276 |
assert_equal 'commit:7234cb27', c.text_tag(Project.find(1)) |
| 277 |
end |
| 278 |
|
| 279 |
def test_text_tag_hash_with_different_project |
| 280 |
c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository) |
| 281 |
assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2)) |
| 282 |
end |
| 283 |
|
| 284 |
def test_text_tag_hash_all_number |
| 285 |
c = Changeset.new(:scmid => '0123456789', :revision => '0123456789') |
| 286 |
assert_equal 'commit:0123456789', c.text_tag |
| 287 |
end |
| 288 |
|
| 289 |
def test_previous |
| 290 |
changeset = Changeset.find_by_revision('3')
|
| 291 |
assert_equal Changeset.find_by_revision('2'), changeset.previous
|
| 292 |
end |
| 293 |
|
| 294 |
def test_previous_nil |
| 295 |
changeset = Changeset.find_by_revision('1')
|
| 296 |
assert_nil changeset.previous |
| 297 |
end |
| 298 |
|
| 299 |
def test_next |
| 300 |
changeset = Changeset.find_by_revision('2')
|
| 301 |
assert_equal Changeset.find_by_revision('3'), changeset.next
|
| 302 |
end |
| 303 |
|
| 304 |
def test_next_nil |
| 305 |
changeset = Changeset.find_by_revision('10')
|
| 306 |
assert_nil changeset.next |
| 307 |
end |
| 308 |
|
| 309 |
def test_comments_should_be_converted_to_utf8 |
| 310 |
proj = Project.find(3) |
| 311 |
# str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
|
| 312 |
str = "Texte encod\xe9 en ISO-8859-1." |
| 313 |
str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
|
| 314 |
r = Repository::Bazaar.create!( |
| 315 |
:project => proj, |
| 316 |
:url => '/tmp/test/bazaar', |
| 317 |
:log_encoding => 'ISO-8859-1' ) |
| 318 |
assert r |
| 319 |
c = Changeset.new(:repository => r, |
| 320 |
:committed_on => Time.now, |
| 321 |
:revision => '123', |
| 322 |
:scmid => '12345', |
| 323 |
:comments => str) |
| 324 |
assert( c.save ) |
| 325 |
str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1." |
| 326 |
str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
|
| 327 |
assert_equal str_utf8, c.comments |
| 328 |
end |
| 329 |
|
| 330 |
def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1 |
| 331 |
proj = Project.find(3) |
| 332 |
# str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
|
| 333 |
str1 = "Texte encod\xe9 en ISO-8859-1." |
| 334 |
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test" |
| 335 |
str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
|
| 336 |
str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
|
| 337 |
r = Repository::Bazaar.create!( |
| 338 |
:project => proj, |
| 339 |
:url => '/tmp/test/bazaar', |
| 340 |
:log_encoding => 'UTF-8' ) |
| 341 |
assert r |
| 342 |
c = Changeset.new(:repository => r, |
| 343 |
:committed_on => Time.now, |
| 344 |
:revision => '123', |
| 345 |
:scmid => '12345', |
| 346 |
:comments => str1, |
| 347 |
:committer => str2) |
| 348 |
assert( c.save ) |
| 349 |
assert_equal "Texte encod? en ISO-8859-1.", c.comments |
| 350 |
assert_equal "?a?b?c?d?e test", c.committer |
| 351 |
end |
| 352 |
|
| 353 |
def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis |
| 354 |
proj = Project.find(3) |
| 355 |
str = "test\xb5\xfetest\xb5\xfe" |
| 356 |
if str.respond_to?(:force_encoding) |
| 357 |
str.force_encoding('ASCII-8BIT')
|
| 358 |
end |
| 359 |
r = Repository::Bazaar.create!( |
| 360 |
:project => proj, |
| 361 |
:url => '/tmp/test/bazaar', |
| 362 |
:log_encoding => 'ISO-2022-JP' ) |
| 363 |
assert r |
| 364 |
c = Changeset.new(:repository => r, |
| 365 |
:committed_on => Time.now, |
| 366 |
:revision => '123', |
| 367 |
:scmid => '12345', |
| 368 |
:comments => str) |
| 369 |
assert( c.save ) |
| 370 |
assert_equal "test??test??", c.comments |
| 371 |
end |
| 372 |
|
| 373 |
def test_comments_should_be_converted_all_latin1_to_utf8 |
| 374 |
s1 = "\xC2\x80" |
| 375 |
s2 = "\xc3\x82\xc2\x80" |
| 376 |
s4 = s2.dup |
| 377 |
if s1.respond_to?(:force_encoding) |
| 378 |
s3 = s1.dup |
| 379 |
s1.force_encoding('ASCII-8BIT')
|
| 380 |
s2.force_encoding('ASCII-8BIT')
|
| 381 |
s3.force_encoding('ISO-8859-1')
|
| 382 |
s4.force_encoding('UTF-8')
|
| 383 |
assert_equal s3.encode('UTF-8'), s4
|
| 384 |
end |
| 385 |
proj = Project.find(3) |
| 386 |
r = Repository::Bazaar.create!( |
| 387 |
:project => proj, |
| 388 |
:url => '/tmp/test/bazaar', |
| 389 |
:log_encoding => 'ISO-8859-1' ) |
| 390 |
assert r |
| 391 |
c = Changeset.new(:repository => r, |
| 392 |
:committed_on => Time.now, |
| 393 |
:revision => '123', |
| 394 |
:scmid => '12345', |
| 395 |
:comments => s1) |
| 396 |
assert( c.save ) |
| 397 |
assert_equal s4, c.comments |
| 398 |
end |
| 399 |
|
| 400 |
def test_invalid_utf8_sequences_in_paths_should_be_replaced |
| 401 |
proj = Project.find(3) |
| 402 |
str1 = "Texte encod\xe9 en ISO-8859-1" |
| 403 |
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test" |
| 404 |
str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
|
| 405 |
str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
|
| 406 |
r = Repository::Bazaar.create!( |
| 407 |
:project => proj, |
| 408 |
:url => '/tmp/test/bazaar', |
| 409 |
:log_encoding => 'UTF-8' ) |
| 410 |
assert r |
| 411 |
cs = Changeset.new( |
| 412 |
:repository => r, |
| 413 |
:committed_on => Time.now, |
| 414 |
:revision => '123', |
| 415 |
:scmid => '12345', |
| 416 |
:comments => "test") |
| 417 |
assert(cs.save) |
| 418 |
ch = Change.new( |
| 419 |
:changeset => cs, |
| 420 |
:action => "A", |
| 421 |
:path => str1, |
| 422 |
:from_path => str2, |
| 423 |
:from_revision => "345") |
| 424 |
assert(ch.save) |
| 425 |
assert_equal "Texte encod? en ISO-8859-1", ch.path |
| 426 |
assert_equal "?a?b?c?d?e test", ch.from_path |
| 427 |
end |
| 428 |
|
| 429 |
def test_comments_nil |
| 430 |
proj = Project.find(3) |
| 431 |
r = Repository::Bazaar.create!( |
| 432 |
:project => proj, |
| 433 |
:url => '/tmp/test/bazaar', |
| 434 |
:log_encoding => 'ISO-8859-1' ) |
| 435 |
assert r |
| 436 |
c = Changeset.new(:repository => r, |
| 437 |
:committed_on => Time.now, |
| 438 |
:revision => '123', |
| 439 |
:scmid => '12345', |
| 440 |
:comments => nil, |
| 441 |
:committer => nil) |
| 442 |
assert( c.save ) |
| 443 |
assert_equal "", c.comments |
| 444 |
assert_equal nil, c.committer |
| 445 |
if c.comments.respond_to?(:force_encoding) |
| 446 |
assert_equal "UTF-8", c.comments.encoding.to_s |
| 447 |
end |
| 448 |
end |
| 449 |
|
| 450 |
def test_comments_empty |
| 451 |
proj = Project.find(3) |
| 452 |
r = Repository::Bazaar.create!( |
| 453 |
:project => proj, |
| 454 |
:url => '/tmp/test/bazaar', |
| 455 |
:log_encoding => 'ISO-8859-1' ) |
| 456 |
assert r |
| 457 |
c = Changeset.new(:repository => r, |
| 458 |
:committed_on => Time.now, |
| 459 |
:revision => '123', |
| 460 |
:scmid => '12345', |
| 461 |
:comments => "", |
| 462 |
:committer => "") |
| 463 |
assert( c.save ) |
| 464 |
assert_equal "", c.comments |
| 465 |
assert_equal "", c.committer |
| 466 |
if c.comments.respond_to?(:force_encoding) |
| 467 |
assert_equal "UTF-8", c.comments.encoding.to_s |
| 468 |
assert_equal "UTF-8", c.committer.encoding.to_s |
| 469 |
end |
| 470 |
end |
| 471 |
|
| 472 |
def test_identifier |
| 473 |
c = Changeset.find_by_revision('1')
|
| 474 |
assert_equal c.revision, c.identifier |
| 475 |
end |
| 476 |
end |