Mercurial > hg > soundsoftware-site
comparison test/unit/issue_relation_test.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | 0c939c159af4 |
children | 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2009 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__) |
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, |
28 :relation_type => IssueRelation::TYPE_PRECEDES | |
28 assert relation.save | 29 assert relation.save |
29 relation.reload | 30 relation.reload |
30 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type | 31 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type |
31 assert_equal from, relation.issue_from | 32 assert_equal from, relation.issue_from |
32 assert_equal to, relation.issue_to | 33 assert_equal to, relation.issue_to |
33 end | 34 end |
34 | 35 |
36 def test_create_minimum | |
37 relation = IssueRelation.new :issue_from => Issue.find(1), :issue_to => Issue.find(2) | |
38 assert relation.save | |
39 assert_equal IssueRelation::TYPE_RELATES, relation.relation_type | |
40 end | |
41 | |
35 def test_follows_relation_should_be_reversed | 42 def test_follows_relation_should_be_reversed |
36 from = Issue.find(1) | 43 from = Issue.find(1) |
37 to = Issue.find(2) | 44 to = Issue.find(2) |
38 | 45 |
39 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_FOLLOWS | 46 relation = IssueRelation.new :issue_from => from, :issue_to => to, |
47 :relation_type => IssueRelation::TYPE_FOLLOWS | |
40 assert relation.save | 48 assert relation.save |
41 relation.reload | 49 relation.reload |
42 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type | 50 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type |
43 assert_equal to, relation.issue_from | 51 assert_equal to, relation.issue_from |
44 assert_equal from, relation.issue_to | 52 assert_equal from, relation.issue_to |
45 end | 53 end |
46 | 54 |
47 # TODO : document why it shouldn't be reversed if validation fails : having | |
48 # relations reversed before the validation would allow simpler code for the | |
49 # validation | |
50 def test_follows_relation_should_not_be_reversed_if_validation_fails | 55 def test_follows_relation_should_not_be_reversed_if_validation_fails |
51 from = Issue.find(1) | 56 from = Issue.find(1) |
52 to = Issue.find(2) | 57 to = Issue.find(2) |
53 | 58 |
54 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_FOLLOWS, :delay => 'xx' | 59 relation = IssueRelation.new :issue_from => from, :issue_to => to, |
60 :relation_type => IssueRelation::TYPE_FOLLOWS, | |
61 :delay => 'xx' | |
55 assert !relation.save | 62 assert !relation.save |
56 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type | 63 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type |
57 assert_equal from, relation.issue_from | 64 assert_equal from, relation.issue_from |
58 assert_equal to, relation.issue_to | 65 assert_equal to, relation.issue_to |
59 end | 66 end |
60 | 67 |
61 def test_relation_type_for | 68 def test_relation_type_for |
62 from = Issue.find(1) | 69 from = Issue.find(1) |
63 to = Issue.find(2) | 70 to = Issue.find(2) |
64 | 71 |
65 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_PRECEDES | 72 relation = IssueRelation.new :issue_from => from, :issue_to => to, |
73 :relation_type => IssueRelation::TYPE_PRECEDES | |
66 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from) | 74 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from) |
67 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to) | 75 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to) |
68 end | 76 end |
69 | 77 |
70 def test_set_issue_to_dates_without_issue_to | 78 def test_set_issue_to_dates_without_issue_to |
71 r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), :relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) | 79 r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), |
80 :relation_type => IssueRelation::TYPE_PRECEDES, | |
81 :delay => 1) | |
72 assert_nil r.set_issue_to_dates | 82 assert_nil r.set_issue_to_dates |
73 end | 83 end |
74 | 84 |
75 def test_set_issue_to_dates_without_issues | 85 def test_set_issue_to_dates_without_issues |
76 r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) | 86 r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) |
77 assert_nil r.set_issue_to_dates | 87 assert_nil r.set_issue_to_dates |
78 end | 88 end |
79 | 89 |
80 def test_validates_circular_dependency | 90 def test_validates_circular_dependency |
81 IssueRelation.delete_all | 91 IssueRelation.delete_all |
82 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_PRECEDES) | 92 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_PRECEDES) |
83 assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_PRECEDES) | 93 assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_PRECEDES) |
84 r = IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_PRECEDES) | 94 r = IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_PRECEDES) |
85 assert !r.save | 95 assert !r.save |
86 assert_not_nil r.errors.on(:base) | 96 assert_not_nil r.errors[:base] |
87 end | 97 end |
88 | 98 |
89 def test_validates_circular_dependency_on_reverse_relations | 99 def test_validates_circular_dependency_on_reverse_relations |
90 IssueRelation.delete_all | 100 IssueRelation.delete_all |
91 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_BLOCKS) | 101 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_BLOCKS) |
92 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_BLOCKED) | 102 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_BLOCKED) |
93 r = IssueRelation.new(:issue_from => Issue.find(2), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_BLOCKED) | 103 r = IssueRelation.new(:issue_from => Issue.find(2), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_BLOCKED) |
94 assert !r.save | 104 assert !r.save |
95 assert_not_nil r.errors.on(:base) | 105 assert_not_nil r.errors[:base] |
96 end | 106 end |
97 end | 107 end |