add journal after creating/deleting issue relation (#1005)

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11885 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2013-05-19 02:09:39 +00:00
parent e5e73a56a7
commit 1f9e1ca318
4 changed files with 117 additions and 1 deletions

View File

@ -306,6 +306,17 @@ module IssuesHelper
end
when 'attachment'
label = l(:label_attachment)
when 'relation'
if detail.value && !detail.old_value
rel_issue = Issue.find_by_id(detail.value)
value = rel_issue.nil? ? "#{l(:label_issue)} #{detail.value}" :
(no_html ? rel_issue : link_to_issue(rel_issue))
elsif detail.old_value && !detail.value
rel_issue = Issue.find_by_id(detail.old_value)
old_value = rel_issue.nil? ? "#{l(:label_issue)} #{detail.old_value}" :
(no_html ? rel_issue : link_to_issue(rel_issue))
end
label = l(detail.prop_key.to_sym)
end
call_hook(:helper_issues_show_detail_after_setting,
{:detail => detail, :label => label, :value => value, :old_value => old_value })
@ -353,7 +364,7 @@ module IssuesHelper
else
l(:text_journal_set_to, :label => label, :value => value).html_safe
end
when 'attachment'
when 'attachment', 'relation'
l(:text_journal_added, :label => label, :value => value).html_safe
end
else

View File

@ -72,6 +72,8 @@ class IssueRelation < ActiveRecord::Base
attr_protected :issue_from_id, :issue_to_id
before_save :handle_issue_order
after_create :create_journal_after_create
after_destroy :create_journal_after_delete
def visible?(user=User.current)
(issue_from.nil? || issue_from.visible?(user)) && (issue_to.nil? || issue_to.visible?(user))
@ -179,4 +181,30 @@ class IssueRelation < ActiveRecord::Base
self.relation_type = TYPES[relation_type][:reverse]
end
end
def create_journal_after_create
journal = issue_from.init_journal(User.current)
journal.details << JournalDetail.new(:property => 'relation',
:prop_key => label_for(issue_from).to_s,
:value => issue_to.id)
journal.save
journal = issue_to.init_journal(User.current)
journal.details << JournalDetail.new(:property => 'relation',
:prop_key => label_for(issue_to).to_s,
:value => issue_from.id)
journal.save
end
def create_journal_after_delete
journal = issue_from.init_journal(User.current)
journal.details << JournalDetail.new(:property => 'relation',
:prop_key => label_for(issue_from).to_s,
:old_value => issue_to.id)
journal.save
journal = issue_to.init_journal(User.current)
journal.details << JournalDetail.new(:property => 'relation',
:prop_key => label_for(issue_to).to_s,
:old_value => issue_from.id)
journal.save
end
end

View File

@ -210,4 +210,36 @@ class IssuesHelperTest < ActionView::TestCase
:old_value => 'error281.txt', :value => nil)
assert_match 'error281.txt', show_detail(detail, true)
end
def test_show_detail_create_relation
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'label_precedes',
:value => 1)
assert_equal "Precedes Bug #1: Can't print recipes added", show_detail(detail, true)
assert_match %r{<strong>Precedes</strong> <i><a href="/issues/1" class=".+">Bug #1</a>: Can&#x27;t print recipes</i> added},
show_detail(detail, false)
non_existed_issue_number = 9999
assert_nil Issue.find_by_id(non_existed_issue_number)
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'label_precedes',
:value => non_existed_issue_number)
assert_equal "Precedes Issue #{non_existed_issue_number} added", show_detail(detail, true)
assert_equal "<strong>Precedes</strong> <i>Issue #{non_existed_issue_number}</i> added", show_detail(detail, false)
end
def test_show_detail_delete_relation
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'label_precedes',
:old_value => 1)
assert_equal "Precedes deleted (Bug #1: Can't print recipes)", show_detail(detail, true)
assert_match %r{<strong>Precedes</strong> deleted \(<del><i><a href="/issues/1" class=".+">Bug #1</a>: Can&#x27;t print recipes</i></del>\)},
show_detail(detail, false)
non_existed_issue_number = 9999
assert_nil Issue.find_by_id(non_existed_issue_number)
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'label_precedes',
:old_value => non_existed_issue_number)
assert_equal "Precedes deleted (Issue 9999)", show_detail(detail, true)
assert_equal "<strong>Precedes</strong> deleted (<del><i>Issue 9999</i></del>)", show_detail(detail, false)
end
end

View File

@ -167,4 +167,49 @@ class IssueRelationTest < ActiveSupport::TestCase
assert !r.save
assert_not_nil r.errors[:base]
end
def test_create_should_make_journal_entry
from = Issue.find(1)
to = Issue.find(2)
from_journals = from.journals.size
to_journals = to.journals.size
relation = IssueRelation.new(:issue_from => from, :issue_to => to,
:relation_type => IssueRelation::TYPE_PRECEDES)
assert relation.save
from.reload
to.reload
relation.reload
assert_equal from.journals.size, (from_journals + 1)
assert_equal to.journals.size, (to_journals + 1)
assert_equal 'relation', from.journals.last.details.last.property
assert_equal 'label_precedes', from.journals.last.details.last.prop_key
assert_equal '2', from.journals.last.details.last.value
assert_nil from.journals.last.details.last.old_value
assert_equal 'relation', to.journals.last.details.last.property
assert_equal 'label_follows', to.journals.last.details.last.prop_key
assert_equal '1', to.journals.last.details.last.value
assert_nil to.journals.last.details.last.old_value
end
def test_delete_should_make_journal_entry
relation = IssueRelation.find(1)
id = relation.id
from = relation.issue_from
to = relation.issue_to
from_journals = from.journals.size
to_journals = to.journals.size
assert relation.destroy
from.reload
to.reload
assert_equal from.journals.size, (from_journals + 1)
assert_equal to.journals.size, (to_journals + 1)
assert_equal 'relation', from.journals.last.details.last.property
assert_equal 'label_blocks', from.journals.last.details.last.prop_key
assert_equal '9', from.journals.last.details.last.old_value
assert_nil from.journals.last.details.last.value
assert_equal 'relation', to.journals.last.details.last.property
assert_equal 'label_blocked_by', to.journals.last.details.last.prop_key
assert_equal '10', to.journals.last.details.last.old_value
assert_nil to.journals.last.details.last.value
end
end