summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2022-11-16 09:24:17 +0000
committerGo MAEDA <maeda@farend.jp>2022-11-16 09:24:17 +0000
commitb3e42149896a6199ee6225f1f6bad8c4778adf1f (patch)
treefdbf124a205bc3fe76d8e20a88b52ca43ce4095c /test/unit
parentf972b5bfa655972b2d469dc79c3b9ba3a971d457 (diff)
downloadredmine-b3e42149896a6199ee6225f1f6bad8c4778adf1f.tar.gz
redmine-b3e42149896a6199ee6225f1f6bad8c4778adf1f.zip
Add the ability to change the author of an issue (#1739).
Patch by Vladimir Kovacik, Jiri Stepanek, Aighan Pacobilch, Olivier Houdas, Takenori TAKAKI, and Mizuki ISHIKAWA. git-svn-id: https://svn.redmine.org/redmine/trunk@21958 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/issue_nested_set_test.rb1
-rw-r--r--test/unit/issue_test.rb52
2 files changed, 53 insertions, 0 deletions
diff --git a/test/unit/issue_nested_set_test.rb b/test/unit/issue_nested_set_test.rb
index ea877c948..37bf1615d 100644
--- a/test/unit/issue_nested_set_test.rb
+++ b/test/unit/issue_nested_set_test.rb
@@ -60,6 +60,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_creating_a_child_in_a_subproject_should_validate
+ User.current = User.find(1)
issue = Issue.generate!
child = nil
assert_difference 'Journal.count', 1 do
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index b056ffb18..6c359618c 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -2789,6 +2789,7 @@ class IssueTest < ActiveSupport::TestCase
end
def test_journalized_multi_custom_field
+ User.current = User.find(1)
field = IssueCustomField.create!(:name => 'filter', :field_format => 'list',
:is_filter => true, :is_for_all => true,
:tracker_ids => [1],
@@ -3465,4 +3466,55 @@ class IssueTest < ActiveSupport::TestCase
r = Issue.like('issue today')
assert_include Issue.find(7), r
end
+
+ def test_author_should_be_changed_when_user_with_permission_change_issue_author
+ Role.all.each do |r|
+ r.add_permission! :change_issue_author
+ end
+ User.current = User.find(2)
+
+ issue = Issue.generate!(:author => User.find(3))
+ assert_equal 3, issue.author_id
+
+ issue.safe_attributes = { 'author_id' => 4 }
+ assert_equal 4, issue.author_id
+ assert_not_equal 3, issue.author_id
+ end
+
+ def test_author_should_not_be_changed_when_user_without_permission_change_issue_author
+ Role.all.each do |r|
+ r.remove_permission! :change_issue_author
+ end
+ User.current = User.find(2)
+
+ issue = Issue.generate!(:author => User.find(3))
+ assert_equal 3, issue.author_id
+
+ issue.safe_attributes = { 'author_id' => 4 }
+ assert_not_equal 4, issue.author_id
+ assert_equal 3, issue.author_id
+ end
+
+ def test_create_should_create_journal_if_user_other_than_current_user_is_set_as_the_author
+ User.current = User.find(1)
+ issue = nil
+ assert_difference 'Journal.count' do
+ issue = Issue.generate!(author: User.find(2))
+ end
+
+ first_journal_detail = issue.journals.first.details.first
+ assert_equal 'author_id', first_journal_detail.prop_key
+ assert_equal '1', first_journal_detail.old_value
+ assert_equal '2', first_journal_detail.value
+ end
+
+ def test_create_should_create_journal_if_current_user_is_set_as_the_author
+ User.current = User.find(1)
+ issue = nil
+ assert_no_difference 'Journal.count' do
+ issue = Issue.generate!(author: User.current)
+ end
+
+ assert_not issue.journals.present?
+ end
end