]> source.dussan.org Git - redmine.git/commitdiff
Overrides IssueRelation#to_s.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 5 Nov 2014 16:14:20 +0000 (16:14 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 5 Nov 2014 16:14:20 +0000 (16:14 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13563 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue_relation.rb
app/views/issues/_relations.html.erb
test/unit/issue_relation_test.rb

index 7248a8868cc4a9dd5aa74351256ea28240e18b46..9eebe1bb099d0bdd8c6f851ded72cf8cd3b3bc14 100644 (file)
@@ -134,6 +134,16 @@ class IssueRelation < ActiveRecord::Base
         :unknow
   end
 
+  def to_s(issue=nil)
+    issue ||= issue_from
+    issue_text = block_given? ? yield(other_issue(issue)) : "##{other_issue(issue).try(:id)}"
+    s = []
+    s << l(label_for(issue))
+    s << "(#{l('datetime.distance_in_words.x_days', :count => delay)})" if delay && delay != 0
+    s << issue_text
+    s.join(' ')
+  end
+
   def css_classes_for(issue)
     "rel-#{relation_type_for(issue)}"
   end
index 049d6f350c27786dd1359f392846ef198a10b9bc..58b5bde3efeb1078b129afc5edddd49a22ddcc52 100644 (file)
   <tr class="issue hascontextmenu" id="relation-<%= relation.id %>">
   <td class="checkbox"><%= check_box_tag("ids[]", other_issue.id, false, :id => nil) %></td>
   <td class="subject">
-    <%= l(relation.label_for(@issue)) %>
-    <%= "(#{l('datetime.distance_in_words.x_days', :count => relation.delay)})" if relation.delay && relation.delay != 0 %>
-    <%= h(other_issue.project) + ' - ' if Setting.cross_project_issue_relations? %>
-    <%= link_to_issue(other_issue, :truncate => 60) %>
+    <%= relation.to_s(@issue) {|other| link_to_issue(other, :truncate => 60, :project => Setting.cross_project_issue_relations?)}.html_safe %>
   </td>
   <td class="status"><%=h other_issue.status.name %></td>
   <td class="start_date"><%= format_date(other_issue.start_date) %></td>
index 086373bd2b09e4a28abe071cbd7a55701d696d38..4b6cbc4c918172d4d04b326c405c34aadd033ce9 100644 (file)
@@ -214,4 +214,23 @@ class IssueRelationTest < ActiveSupport::TestCase
     assert_equal '10', to.journals.last.details.last.old_value
     assert_nil   to.journals.last.details.last.value
   end
+
+  def test_to_s_should_return_the_relation_string
+    set_language_if_valid 'en'
+    relation = IssueRelation.find(1)
+    assert_equal "Blocks #9", relation.to_s(relation.issue_from)
+    assert_equal "Blocked by #10", relation.to_s(relation.issue_to)
+  end
+
+  def test_to_s_without_argument_should_return_the_relation_string_for_issue_from
+    set_language_if_valid 'en'
+    relation = IssueRelation.find(1)
+    assert_equal "Blocks #9", relation.to_s
+  end
+
+  def test_to_s_should_accept_a_block_as_custom_issue_formatting
+    set_language_if_valid 'en'
+    relation = IssueRelation.find(1)
+    assert_equal "Blocks Bug #9", relation.to_s {|issue| "#{issue.tracker} ##{issue.id}"}
+  end
 end