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