# HG changeset patch
# User Toshi MARUYAMA
# Date 1357553213 -32400
# Node ID 1d7ba401e0cf4ca2d8cb337946cb1a1a24beaf2c
# Parent  cdc60b1037349567daa6b64b791795cfca0d79c6
(#1005)

diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb
--- a/app/models/issue_relation.rb
+++ b/app/models/issue_relation.rb
@@ -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,34 @@ 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
+
+    # issue-to
+    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
+
+    # issue-to
+    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
# HG changeset patch
# User Toshi MARUYAMA
# Date 1357553214 -32400
# Node ID 6fe48eac53f44d828104ac6221525dff79b30515
# Parent  1d7ba401e0cf4ca2d8cb337946cb1a1a24beaf2c
(#1005)

diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -290,6 +290,14 @@ module IssuesHelper
       end
     when 'attachment'
       label = l(:label_attachment)
+    when 'relation'
+      if detail.value && !detail.old_value
+        value = link_to_issue(Issue.find(detail.value))
+        label = l(detail.prop_key.to_sym)
+      elsif detail.old_value && !detail.value
+        old_value = link_to_issue(Issue.find(detail.old_value)) if detail.old_value
+        label = l(detail.prop_key.to_sym)
+      end
     end
     call_hook(:helper_issues_show_detail_after_setting,
               {:detail => detail, :label => label, :value => value, :old_value => old_value })
@@ -339,6 +347,8 @@ module IssuesHelper
         end
       when 'attachment'
         l(:text_journal_added, :label => label, :value => value).html_safe
+      when 'relation'
+        l(:text_journal_added, :label => label, :value => value).html_safe
       end
     else
       l(:text_journal_deleted, :label => label, :old => old_value).html_safe
# HG changeset patch
# User Toshi MARUYAMA
# Date 1357554753 -32400
# Node ID 0bc6f22eeb1582e73c645884e00843312a7f0926
# Parent  6fe48eac53f44d828104ac6221525dff79b30515
(#1005)

diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -309,7 +309,9 @@ module IssuesHelper
     unless no_html
       label = content_tag('strong', label)
       old_value = content_tag("i", h(old_value)) if detail.old_value
-      old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
+      if detail.old_value and detail.value.blank? and detail.property != 'relation'
+        old_value = content_tag("del", old_value)
+      end
       if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
         # Link to the attachment if it has not been removed
         value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
# HG changeset patch
# User Toshi MARUYAMA
# Date 1357554754 -32400
# Node ID e5ab0f0f24634f4ac1156844b80c59a193b8b192
# Parent  0bc6f22eeb1582e73c645884e00843312a7f0926
(#1005)

diff --git a/test/unit/issue_relation_test.rb b/test/unit/issue_relation_test.rb
--- a/test/unit/issue_relation_test.rb
+++ b/test/unit/issue_relation_test.rb
@@ -132,4 +132,38 @@ class IssueRelationTest < ActiveSupport:
     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)
+  end
+
+  def test_delete_should_make_journal_entry
+    relation = issue_relations(:issue_relation_001)
+    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)
+  end
 end
# HG changeset patch
# User Toshi MARUYAMA
# Date 1357554754 -32400
# Node ID c184ecd9276f9eb192ac9983dd3b91e56750a364
# Parent  e5ab0f0f24634f4ac1156844b80c59a193b8b192
(#1005)

diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -1137,7 +1137,8 @@ class IssueTest < ActiveSupport::TestCas
     should "not create a journal" do
       copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
       copy.save!
-      assert_equal 0, copy.reload.journals.size
+      prev_journal_count = copy.journals.size
+      assert_equal prev_journal_count, copy.reload.journals.size
     end
 
     should "allow assigned_to changes" do
