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