diff test/unit/changeset_test.rb @ 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 433d4f72a19b
children e248c7af89ec
line wrap: on
line diff
--- a/test/unit/changeset_test.rb	Fri Jun 14 09:05:06 2013 +0100
+++ b/test/unit/changeset_test.rb	Tue Jan 14 14:37:42 2014 +0000
@@ -1,7 +1,7 @@
 # encoding: utf-8
 #
 # Redmine - project management software
-# Copyright (C) 2006-2012  Jean-Philippe Lang
+# Copyright (C) 2006-2013  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -30,11 +30,8 @@
 
   def test_ref_keywords_any
     ActionMailer::Base.deliveries.clear
-    Setting.commit_fix_status_id = IssueStatus.find(
-                                   :first, :conditions => ["is_closed = ?", true]).id
-    Setting.commit_fix_done_ratio = '90'
     Setting.commit_ref_keywords = '*'
-    Setting.commit_fix_keywords = 'fixes , closes'
+    Setting.commit_update_keywords = [{'keywords' => 'fixes , closes', 'status_id' => '5', 'done_ratio' => '90'}]
 
     c = Changeset.new(:repository   => Project.find(1).repository,
                       :committed_on => Time.now,
@@ -50,7 +47,7 @@
 
   def test_ref_keywords
     Setting.commit_ref_keywords = 'refs'
-    Setting.commit_fix_keywords = ''
+    Setting.commit_update_keywords = ''
     c = Changeset.new(:repository   => Project.find(1).repository,
                       :committed_on => Time.now,
                       :comments     => 'Ignores #2. Refs #1',
@@ -61,7 +58,7 @@
 
   def test_ref_keywords_any_only
     Setting.commit_ref_keywords = '*'
-    Setting.commit_fix_keywords = ''
+    Setting.commit_update_keywords = ''
     c = Changeset.new(:repository   => Project.find(1).repository,
                       :committed_on => Time.now,
                       :comments     => 'Ignores #2. Refs #1',
@@ -113,10 +110,8 @@
   end
 
   def test_ref_keywords_closing_with_timelog
-    Setting.commit_fix_status_id = IssueStatus.find(
-                                    :first, :conditions => ["is_closed = ?", true]).id
     Setting.commit_ref_keywords = '*'
-    Setting.commit_fix_keywords = 'fixes , closes'
+    Setting.commit_update_keywords = [{'keywords' => 'fixes , closes', 'status_id' => IssueStatus.where(:is_closed => true).first.id.to_s}]
     Setting.commit_logtime_enabled = '1'
 
     c = Changeset.new(:repository   => Project.find(1).repository,
@@ -165,6 +160,48 @@
     assert_equal [1,2,3], c.issue_ids.sort
   end
 
+  def test_update_keywords_with_multiple_rules
+    with_settings :commit_update_keywords => [
+      {'keywords' => 'fixes, closes', 'status_id' => '5'},
+      {'keywords' => 'resolves', 'status_id' => '3'}
+    ] do
+
+      issue1 = Issue.generate!
+      issue2 = Issue.generate!
+      Changeset.generate!(:comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}")
+      assert_equal 5, issue1.reload.status_id
+      assert_equal 3, issue2.reload.status_id
+    end
+  end
+
+  def test_update_keywords_with_multiple_rules_should_match_tracker
+    with_settings :commit_update_keywords => [
+      {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
+      {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => ''}
+    ] do
+
+      issue1 = Issue.generate!(:tracker_id => 2)
+      issue2 = Issue.generate!
+      Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
+      assert_equal 5, issue1.reload.status_id
+      assert_equal 3, issue2.reload.status_id
+    end
+  end
+
+  def test_update_keywords_with_multiple_rules_and_no_match
+    with_settings :commit_update_keywords => [
+      {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
+      {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => '3'}
+    ] do
+
+      issue1 = Issue.generate!(:tracker_id => 2)
+      issue2 = Issue.generate!
+      Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
+      assert_equal 5, issue1.reload.status_id
+      assert_equal 1, issue2.reload.status_id # no updates
+    end
+  end
+
   def test_commit_referencing_a_subproject_issue
     c = Changeset.new(:repository   => Project.find(1).repository,
                       :committed_on => Time.now,
@@ -176,7 +213,7 @@
   end
 
   def test_commit_closing_a_subproject_issue
-    with_settings :commit_fix_status_id => 5, :commit_fix_keywords => 'closes',
+    with_settings :commit_update_keywords => [{'keywords' => 'closes', 'status_id' => '5'}],
                   :default_language => 'en' do
       issue = Issue.find(5)
       assert !issue.closed?
@@ -238,6 +275,28 @@
     end
   end
 
+  def test_old_commits_should_not_update_issues_nor_log_time
+    Setting.commit_ref_keywords = '*'
+    Setting.commit_update_keywords = {'fixes , closes' => {'status_id' => '5', 'done_ratio' => '90'}}
+    Setting.commit_logtime_enabled = '1'
+
+    repository = Project.find(1).repository
+    repository.created_on = Time.now
+    repository.save!
+
+    c = Changeset.new(:repository   => repository,
+                      :committed_on => 1.month.ago,
+                      :comments     => 'New commit (#2). Fixes #1 @1h',
+                      :revision     => '12345')
+    assert_no_difference 'TimeEntry.count' do
+      assert c.save
+    end
+    assert_equal [1, 2], c.issue_ids.sort
+    issue = Issue.find(1)
+    assert_equal 1, issue.status_id
+    assert_equal 0, issue.done_ratio
+  end
+
   def test_text_tag_revision
     c = Changeset.new(:revision => '520')
     assert_equal 'r520', c.text_tag