Mercurial > hg > soundsoftware-site
diff test/unit/changeset_test.rb @ 1526:404aa68d4227
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 12:46:20 +0100 |
parents | dffacf8a6908 |
children |
line wrap: on
line diff
--- a/test/unit/changeset_test.rb Mon Mar 17 08:57:04 2014 +0000 +++ b/test/unit/changeset_test.rb Thu Sep 11 12:46:20 2014 +0100 @@ -1,7 +1,7 @@ # encoding: utf-8 # # Redmine - project management software -# Copyright (C) 2006-2012 Jean-Philippe Lang +# Copyright (C) 2006-2014 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', @@ -99,7 +96,7 @@ end assert_equal [1], c.issue_ids.sort - time = TimeEntry.first(:order => 'id desc') + time = TimeEntry.order('id desc').first assert_equal 1, time.issue_id assert_equal 1, time.project_id assert_equal 2, time.user_id @@ -113,10 +110,9 @@ 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, @@ -131,7 +127,7 @@ assert Issue.find(1).closed? assert Issue.find(2).closed? - times = TimeEntry.all(:order => 'id desc', :limit => 2) + times = TimeEntry.order('id desc').limit(2) assert_equal [1, 2], times.collect(&:issue_id).sort end @@ -165,6 +161,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 +214,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? @@ -188,7 +226,7 @@ assert c.save end assert issue.reload.closed? - journal = Journal.first(:order => 'id DESC') + journal = Journal.order('id DESC').first assert_equal issue, journal.issue assert_include "Applied in changeset ecookbook:r12345.", journal.notes end @@ -212,7 +250,6 @@ r = Repository::Subversion.create!( :project => Project.find(3), :url => 'svn://localhost/test') - with_settings :commit_cross_project_ref => '0' do c = Changeset.new(:repository => r, :committed_on => Time.now, @@ -227,7 +264,6 @@ r = Repository::Subversion.create!( :project => Project.find(3), :url => 'svn://localhost/test') - with_settings :commit_cross_project_ref => '1' do c = Changeset.new(:repository => r, :committed_on => Time.now, @@ -238,6 +274,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 @@ -258,7 +316,6 @@ :project_id => 1, :url => 'svn://localhost/test', :identifier => 'documents') - c = Changeset.new(:revision => '520', :repository => r) assert_equal 'documents|r520', c.text_tag assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2)) @@ -286,6 +343,16 @@ assert_equal 'commit:0123456789', c.text_tag end + def test_text_tag_hash_with_repository_identifier + r = Repository::Subversion.new( + :project_id => 1, + :url => 'svn://localhost/test', + :identifier => 'documents') + c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => r) + assert_equal 'commit:documents|7234cb27', c.text_tag + assert_equal 'ecookbook:commit:documents|7234cb27', c.text_tag(Project.find(2)) + end + def test_previous changeset = Changeset.find_by_revision('3') assert_equal Changeset.find_by_revision('2'), changeset.previous @@ -469,6 +536,17 @@ end end + def test_comments_should_accept_more_than_64k + c = Changeset.new(:repository => Repository.first, + :committed_on => Time.now, + :revision => '123', + :scmid => '12345', + :comments => "a" * 500.kilobyte) + assert c.save + c.reload + assert_equal 500.kilobyte, c.comments.size + end + def test_identifier c = Changeset.find_by_revision('1') assert_equal c.revision, c.identifier