@@ -27,13 +27,13 class IssueRelation < ActiveRecord::Base | |||
|
27 | 27 | TYPE_PRECEDES = "precedes" |
|
28 | 28 | TYPE_FOLLOWS = "follows" |
|
29 | 29 | |
|
30 | TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1 }, | |
|
31 | TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2 }, | |
|
32 | TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, :order => 3, :reverse => TYPE_DUPLICATES }, | |
|
33 | TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 4 }, | |
|
34 | TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, :order => 5, :reverse => TYPE_BLOCKS }, | |
|
35 | TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 6 }, | |
|
36 | TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 7, :reverse => TYPE_PRECEDES } | |
|
30 | TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1, :sym => TYPE_RELATES }, | |
|
31 | TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2, :sym => TYPE_DUPLICATED }, | |
|
32 | TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, :order => 3, :sym => TYPE_DUPLICATES, :reverse => TYPE_DUPLICATES }, | |
|
33 | TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 4, :sym => TYPE_BLOCKED }, | |
|
34 | TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS }, | |
|
35 | TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 6, :sym => TYPE_FOLLOWS }, | |
|
36 | TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES } | |
|
37 | 37 | }.freeze |
|
38 | 38 | |
|
39 | 39 | validates_presence_of :issue_from, :issue_to, :relation_type |
@@ -56,6 +56,17 class IssueRelation < ActiveRecord::Base | |||
|
56 | 56 | (self.issue_from_id == issue.id) ? issue_to : issue_from |
|
57 | 57 | end |
|
58 | 58 | |
|
59 | # Returns the relation type for +issue+ | |
|
60 | def relation_type_for(issue) | |
|
61 | if TYPES[relation_type] | |
|
62 | if self.issue_from_id == issue.id | |
|
63 | relation_type | |
|
64 | else | |
|
65 | TYPES[relation_type][:sym] | |
|
66 | end | |
|
67 | end | |
|
68 | end | |
|
69 | ||
|
59 | 70 | def label_for(issue) |
|
60 | 71 | TYPES[relation_type] ? TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : :unknow |
|
61 | 72 | end |
@@ -30,6 +30,12 xml.issue do | |||
|
30 | 30 | xml.created_on @issue.created_on |
|
31 | 31 | xml.updated_on @issue.updated_on |
|
32 | 32 | |
|
33 | xml.relations do | |
|
34 | @issue.relations.select {|r| r.other_issue(@issue).visible? }.each do |relation| | |
|
35 | xml.relation(:id => relation.id, :issue_id => relation.other_issue(@issue).id, :relation_type => relation.relation_type_for(@issue), :delay => relation.delay) | |
|
36 | end | |
|
37 | end | |
|
38 | ||
|
33 | 39 | xml.changesets do |
|
34 | 40 | @issue.changesets.each do |changeset| |
|
35 | 41 | xml.changeset :revision => changeset.revision do |
@@ -54,4 +54,13 class IssueRelationTest < ActiveSupport::TestCase | |||
|
54 | 54 | assert_equal from, relation.issue_from |
|
55 | 55 | assert_equal to, relation.issue_to |
|
56 | 56 | end |
|
57 | ||
|
58 | def test_relation_type_for | |
|
59 | from = Issue.find(1) | |
|
60 | to = Issue.find(2) | |
|
61 | ||
|
62 | relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_PRECEDES | |
|
63 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from) | |
|
64 | assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to) | |
|
65 | end | |
|
57 | 66 | end |
General Comments 0
You need to be logged in to leave comments.
Login now