summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-10-13 07:37:49 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-10-13 07:37:49 +0000
commitb6cb7aa8e3b98db4095a1869d1ce51aefaf308db (patch)
treef0b496dd9b19c52b1c499af33802c229d570862a /test
parentb8aa4da28a1e61d3d14e296cddd3584d505da3c3 (diff)
downloadredmine-b6cb7aa8e3b98db4095a1869d1ce51aefaf308db.tar.gz
redmine-b6cb7aa8e3b98db4095a1869d1ce51aefaf308db.zip
Ability to define commit keywords per tracker (#7590).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12208 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/functional/settings_controller_test.rb34
-rw-r--r--test/object_helpers.rb12
-rw-r--r--test/unit/changeset_test.rb61
-rw-r--r--test/unit/repository_test.rb6
4 files changed, 75 insertions, 38 deletions
diff --git a/test/functional/settings_controller_test.rb b/test/functional/settings_controller_test.rb
index b3cf7bd5a..f5d4377f1 100644
--- a/test/functional/settings_controller_test.rb
+++ b/test/functional/settings_controller_test.rb
@@ -81,38 +81,41 @@ class SettingsControllerTest < ActionController::TestCase
end
def test_edit_commit_update_keywords
- with_settings :commit_update_keywords => {
- "fixes, resolves" => {"status_id" => "3"},
- "closes" => {"status_id" => "5", "done_ratio" => "100"}
- } do
+ with_settings :commit_update_keywords => [
+ {"keywords" => "fixes, resolves", "status_id" => "3"},
+ {"keywords" => "closes", "status_id" => "5", "done_ratio" => "100", "if_tracker_id" => "2"}
+ ] do
get :edit
end
assert_response :success
assert_select 'tr.commit-keywords', 2
- assert_select 'tr.commit-keywords' do
+ assert_select 'tr.commit-keywords:nth-child(1)' do
assert_select 'input[name=?][value=?]', 'settings[commit_update_keywords][keywords][]', 'fixes, resolves'
assert_select 'select[name=?]', 'settings[commit_update_keywords][status_id][]' do
assert_select 'option[value=3][selected=selected]'
end
end
- assert_select 'tr.commit-keywords' do
+ assert_select 'tr.commit-keywords:nth-child(2)' do
assert_select 'input[name=?][value=?]', 'settings[commit_update_keywords][keywords][]', 'closes'
assert_select 'select[name=?]', 'settings[commit_update_keywords][status_id][]' do
- assert_select 'option[value=5][selected=selected]'
+ assert_select 'option[value=5][selected=selected]', :text => 'Closed'
end
assert_select 'select[name=?]', 'settings[commit_update_keywords][done_ratio][]' do
- assert_select 'option[value=100][selected=selected]'
+ assert_select 'option[value=100][selected=selected]', :text => '100 %'
+ end
+ assert_select 'select[name=?]', 'settings[commit_update_keywords][if_tracker_id][]' do
+ assert_select 'option[value=2][selected=selected]', :text => 'Feature request'
end
end
end
def test_edit_without_commit_update_keywords_should_show_blank_line
- with_settings :commit_update_keywords => {} do
+ with_settings :commit_update_keywords => [] do
get :edit
end
assert_response :success
assert_select 'tr.commit-keywords', 1 do
- assert_select 'input[name=?][value=?]', 'settings[commit_update_keywords][keywords][]', ''
+ assert_select 'input[name=?]:not([value])', 'settings[commit_update_keywords][keywords][]'
end
end
@@ -121,14 +124,15 @@ class SettingsControllerTest < ActionController::TestCase
:commit_update_keywords => {
:keywords => ["resolves", "closes"],
:status_id => ["3", "5"],
- :done_ratio => ["", "100"]
+ :done_ratio => ["", "100"],
+ :if_tracker_id => ["", "2"]
}
}
assert_redirected_to '/settings'
- assert_equal({
- "resolves" => {"status_id" => "3"},
- "closes" => {"status_id" => "5", "done_ratio" => "100"}
- }, Setting.commit_update_keywords)
+ assert_equal([
+ {"keywords" => "resolves", "status_id" => "3"},
+ {"keywords" => "closes", "status_id" => "5", "done_ratio" => "100", "if_tracker_id" => "2"}
+ ], Setting.commit_update_keywords)
end
def test_get_plugin_settings
diff --git a/test/object_helpers.rb b/test/object_helpers.rb
index 2f7559249..9cb0916f7 100644
--- a/test/object_helpers.rb
+++ b/test/object_helpers.rb
@@ -166,4 +166,16 @@ module ObjectHelpers
field.save!
field
end
+
+ def Changeset.generate!(attributes={})
+ @generated_changeset_rev ||= '123456'
+ @generated_changeset_rev.succ!
+ changeset = new(attributes)
+ changeset.repository ||= Project.find(1).repository
+ changeset.revision ||= @generated_changeset_rev
+ changeset.committed_on ||= Time.now
+ yield changeset if block_given?
+ changeset.save!
+ changeset
+ end
end
diff --git a/test/unit/changeset_test.rb b/test/unit/changeset_test.rb
index 93bd7bba5..0eea5f88b 100644
--- a/test/unit/changeset_test.rb
+++ b/test/unit/changeset_test.rb
@@ -31,7 +31,7 @@ class ChangesetTest < ActiveSupport::TestCase
def test_ref_keywords_any
ActionMailer::Base.deliveries.clear
Setting.commit_ref_keywords = '*'
- Setting.commit_update_keywords = {'fixes , closes' => {'status_id' => '5', 'done_ratio' => '90'}}
+ 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,
@@ -111,11 +111,7 @@ class ChangesetTest < ActiveSupport::TestCase
def test_ref_keywords_closing_with_timelog
Setting.commit_ref_keywords = '*'
- Setting.commit_update_keywords = {
- 'fixes , closes' => {
- 'status_id' => IssueStatus.where(:is_closed => true).first.id.to_s
- }
- }
+ 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,20 +161,45 @@ class ChangesetTest < ActiveSupport::TestCase
end
def test_update_keywords_with_multiple_rules
- Setting.commit_update_keywords = {
- 'fixes, closes' => {'status_id' => '5'},
- 'resolves' => {'status_id' => '3'}
- }
- issue1 = Issue.generate!
- issue2 = Issue.generate!
+ 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
- c = Changeset.new(:repository => Project.find(1).repository,
- :committed_on => Time.now,
- :comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}",
- :revision => '12345')
- assert c.save
- assert_equal 5, issue1.reload.status_id
- assert_equal 3, issue2.reload.status_id
+ 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
@@ -192,7 +213,7 @@ class ChangesetTest < ActiveSupport::TestCase
end
def test_commit_closing_a_subproject_issue
- with_settings :commit_update_keywords => {'closes' => {'status_id' => '5'}},
+ with_settings :commit_update_keywords => [{'keywords' => 'closes', 'status_id' => '5'}],
:default_language => 'en' do
issue = Issue.find(5)
assert !issue.closed?
diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb
index 3ff9fc51e..c269df7bb 100644
--- a/test/unit/repository_test.rb
+++ b/test/unit/repository_test.rb
@@ -183,9 +183,9 @@ class RepositoryTest < ActiveSupport::TestCase
Setting.default_language = 'en'
Setting.commit_ref_keywords = 'refs , references, IssueID'
- Setting.commit_update_keywords = {
- 'fixes , closes' => {'status_id' => IssueStatus.where(:is_closed => true).first.id, 'done_ratio' => '90'}
- }
+ Setting.commit_update_keywords = [
+ {'keywords' => 'fixes , closes', 'status_id' => IssueStatus.where(:is_closed => true).first.id, 'done_ratio' => '90'}
+ ]
Setting.default_language = 'en'
ActionMailer::Base.deliveries.clear