@@ -1,100 +1,101 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 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 :issue_relations, :issues |
|
22 | 22 | |
|
23 | 23 | def test_create |
|
24 | 24 | from = Issue.find(1) |
|
25 | 25 | to = Issue.find(2) |
|
26 | 26 | |
|
27 |
relation = IssueRelation.new :issue_from => from, :issue_to => to, |
|
|
27 | relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
|
28 | :relation_type => IssueRelation::TYPE_PRECEDES | |
|
28 | 29 | assert relation.save |
|
29 | 30 | relation.reload |
|
30 | 31 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type |
|
31 | 32 | assert_equal from, relation.issue_from |
|
32 | 33 | assert_equal to, relation.issue_to |
|
33 | 34 | end |
|
34 | 35 | |
|
35 | 36 | def test_create_minimum |
|
36 | 37 | relation = IssueRelation.new :issue_from => Issue.find(1), :issue_to => Issue.find(2) |
|
37 | 38 | assert relation.save |
|
38 | 39 | assert_equal IssueRelation::TYPE_RELATES, relation.relation_type |
|
39 | 40 | end |
|
40 | 41 | |
|
41 | 42 | def test_follows_relation_should_be_reversed |
|
42 | 43 | from = Issue.find(1) |
|
43 | 44 | to = Issue.find(2) |
|
44 | 45 | |
|
45 | 46 | relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_FOLLOWS |
|
46 | 47 | assert relation.save |
|
47 | 48 | relation.reload |
|
48 | 49 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type |
|
49 | 50 | assert_equal to, relation.issue_from |
|
50 | 51 | assert_equal from, relation.issue_to |
|
51 | 52 | end |
|
52 | 53 | |
|
53 | 54 | def test_follows_relation_should_not_be_reversed_if_validation_fails |
|
54 | 55 | from = Issue.find(1) |
|
55 | 56 | to = Issue.find(2) |
|
56 | 57 | |
|
57 | 58 | relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_FOLLOWS, :delay => 'xx' |
|
58 | 59 | assert !relation.save |
|
59 | 60 | assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type |
|
60 | 61 | assert_equal from, relation.issue_from |
|
61 | 62 | assert_equal to, relation.issue_to |
|
62 | 63 | end |
|
63 | 64 | |
|
64 | 65 | def test_relation_type_for |
|
65 | 66 | from = Issue.find(1) |
|
66 | 67 | to = Issue.find(2) |
|
67 | 68 | |
|
68 | 69 | relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_PRECEDES |
|
69 | 70 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from) |
|
70 | 71 | assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to) |
|
71 | 72 | end |
|
72 | 73 | |
|
73 | 74 | def test_set_issue_to_dates_without_issue_to |
|
74 | 75 | r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), :relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) |
|
75 | 76 | assert_nil r.set_issue_to_dates |
|
76 | 77 | end |
|
77 | 78 | |
|
78 | 79 | def test_set_issue_to_dates_without_issues |
|
79 | 80 | r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) |
|
80 | 81 | assert_nil r.set_issue_to_dates |
|
81 | 82 | end |
|
82 | 83 | |
|
83 | 84 | def test_validates_circular_dependency |
|
84 | 85 | IssueRelation.delete_all |
|
85 | 86 | assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_PRECEDES) |
|
86 | 87 | assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_PRECEDES) |
|
87 | 88 | r = IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_PRECEDES) |
|
88 | 89 | assert !r.save |
|
89 | 90 | assert_not_nil r.errors[:base] |
|
90 | 91 | end |
|
91 | 92 | |
|
92 | 93 | def test_validates_circular_dependency_on_reverse_relations |
|
93 | 94 | IssueRelation.delete_all |
|
94 | 95 | assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_BLOCKS) |
|
95 | 96 | assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_BLOCKED) |
|
96 | 97 | r = IssueRelation.new(:issue_from => Issue.find(2), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_BLOCKED) |
|
97 | 98 | assert !r.save |
|
98 | 99 | assert_not_nil r.errors[:base] |
|
99 | 100 | end |
|
100 | 101 | end |
General Comments 0
You need to be logged in to leave comments.
Login now