@@ -1,117 +1,135 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class IssueRelationTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :projects, |
|
22 | 22 | :users, |
|
23 | 23 | :roles, |
|
24 | 24 | :members, |
|
25 | 25 | :member_roles, |
|
26 | 26 | :issues, |
|
27 | 27 | :issue_statuses, |
|
28 | 28 | :issue_relations, |
|
29 | 29 | :enabled_modules, |
|
30 | 30 | :enumerations, |
|
31 | 31 | :trackers |
|
32 | 32 | |
|
33 | 33 | def test_create |
|
34 | 34 | from = Issue.find(1) |
|
35 | 35 | to = Issue.find(2) |
|
36 | 36 | |
|
37 | 37 | relation = IssueRelation.new :issue_from => from, :issue_to => to, |
|
38 | 38 | :relation_type => IssueRelation::TYPE_PRECEDES |
|
39 | 39 | assert relation.save |
|
40 | 40 | relation.reload |
|
41 | 41 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type |
|
42 | 42 | assert_equal from, relation.issue_from |
|
43 | 43 | assert_equal to, relation.issue_to |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def test_create_minimum |
|
47 | 47 | relation = IssueRelation.new :issue_from => Issue.find(1), :issue_to => Issue.find(2) |
|
48 | 48 | assert relation.save |
|
49 | 49 | assert_equal IssueRelation::TYPE_RELATES, relation.relation_type |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def test_follows_relation_should_be_reversed |
|
53 | 53 | from = Issue.find(1) |
|
54 | 54 | to = Issue.find(2) |
|
55 | 55 | |
|
56 | 56 | relation = IssueRelation.new :issue_from => from, :issue_to => to, |
|
57 | 57 | :relation_type => IssueRelation::TYPE_FOLLOWS |
|
58 | 58 | assert relation.save |
|
59 | 59 | relation.reload |
|
60 | 60 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type |
|
61 | 61 | assert_equal to, relation.issue_from |
|
62 | 62 | assert_equal from, relation.issue_to |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def test_follows_relation_should_not_be_reversed_if_validation_fails |
|
66 | 66 | from = Issue.find(1) |
|
67 | 67 | to = Issue.find(2) |
|
68 | 68 | |
|
69 | 69 | relation = IssueRelation.new :issue_from => from, :issue_to => to, |
|
70 | 70 | :relation_type => IssueRelation::TYPE_FOLLOWS, |
|
71 | 71 | :delay => 'xx' |
|
72 | 72 | assert !relation.save |
|
73 | 73 | assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type |
|
74 | 74 | assert_equal from, relation.issue_from |
|
75 | 75 | assert_equal to, relation.issue_to |
|
76 | 76 | end |
|
77 | 77 | |
|
78 | 78 | def test_relation_type_for |
|
79 | 79 | from = Issue.find(1) |
|
80 | 80 | to = Issue.find(2) |
|
81 | 81 | |
|
82 | 82 | relation = IssueRelation.new :issue_from => from, :issue_to => to, |
|
83 | 83 | :relation_type => IssueRelation::TYPE_PRECEDES |
|
84 | 84 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from) |
|
85 | 85 | assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to) |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | def test_set_issue_to_dates_without_issue_to |
|
89 | 89 | r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), |
|
90 | 90 | :relation_type => IssueRelation::TYPE_PRECEDES, |
|
91 | 91 | :delay => 1) |
|
92 | 92 | assert_nil r.set_issue_to_dates |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | def test_set_issue_to_dates_without_issues |
|
96 | 96 | r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) |
|
97 | 97 | assert_nil r.set_issue_to_dates |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | 100 | def test_validates_circular_dependency |
|
101 | 101 | IssueRelation.delete_all |
|
102 | assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_PRECEDES) | |
|
103 | assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_PRECEDES) | |
|
104 |
|
|
|
102 | assert IssueRelation.create!( | |
|
103 | :issue_from => Issue.find(1), :issue_to => Issue.find(2), | |
|
104 | :relation_type => IssueRelation::TYPE_PRECEDES | |
|
105 | ) | |
|
106 | assert IssueRelation.create!( | |
|
107 | :issue_from => Issue.find(2), :issue_to => Issue.find(3), | |
|
108 | :relation_type => IssueRelation::TYPE_PRECEDES | |
|
109 | ) | |
|
110 | r = IssueRelation.new( | |
|
111 | :issue_from => Issue.find(3), :issue_to => Issue.find(1), | |
|
112 | :relation_type => IssueRelation::TYPE_PRECEDES | |
|
113 | ) | |
|
105 | 114 | assert !r.save |
|
106 | 115 | assert_not_nil r.errors[:base] |
|
107 | 116 | end |
|
108 | 117 | |
|
109 | 118 | def test_validates_circular_dependency_on_reverse_relations |
|
110 | 119 | IssueRelation.delete_all |
|
111 | assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_BLOCKS) | |
|
112 | assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_BLOCKED) | |
|
113 | r = IssueRelation.new(:issue_from => Issue.find(2), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_BLOCKED) | |
|
120 | assert IssueRelation.create!( | |
|
121 | :issue_from => Issue.find(1), :issue_to => Issue.find(3), | |
|
122 | :relation_type => IssueRelation::TYPE_BLOCKS | |
|
123 | ) | |
|
124 | assert IssueRelation.create!( | |
|
125 | :issue_from => Issue.find(1), :issue_to => Issue.find(2), | |
|
126 | :relation_type => IssueRelation::TYPE_BLOCKED | |
|
127 | ) | |
|
128 | r = IssueRelation.new( | |
|
129 | :issue_from => Issue.find(2), :issue_to => Issue.find(1), | |
|
130 | :relation_type => IssueRelation::TYPE_BLOCKED | |
|
131 | ) | |
|
114 | 132 | assert !r.save |
|
115 | 133 | assert_not_nil r.errors[:base] |
|
116 | 134 | end |
|
117 | 135 | end |
General Comments 0
You need to be logged in to leave comments.
Login now