##// END OF EJS Templates
code layout clean up of test_follows_relation_should_not_be_reversed_if_validation_fails at test/unit/issue_relation_test.rb...
Toshi MARUYAMA -
r7481:33349c93db6f
parent child
Show More
@@ -1,102 +1,104
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 27 relation = IssueRelation.new :issue_from => from, :issue_to => to,
28 28 :relation_type => IssueRelation::TYPE_PRECEDES
29 29 assert relation.save
30 30 relation.reload
31 31 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type
32 32 assert_equal from, relation.issue_from
33 33 assert_equal to, relation.issue_to
34 34 end
35 35
36 36 def test_create_minimum
37 37 relation = IssueRelation.new :issue_from => Issue.find(1), :issue_to => Issue.find(2)
38 38 assert relation.save
39 39 assert_equal IssueRelation::TYPE_RELATES, relation.relation_type
40 40 end
41 41
42 42 def test_follows_relation_should_be_reversed
43 43 from = Issue.find(1)
44 44 to = Issue.find(2)
45 45
46 46 relation = IssueRelation.new :issue_from => from, :issue_to => to,
47 47 :relation_type => IssueRelation::TYPE_FOLLOWS
48 48 assert relation.save
49 49 relation.reload
50 50 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type
51 51 assert_equal to, relation.issue_from
52 52 assert_equal from, relation.issue_to
53 53 end
54 54
55 55 def test_follows_relation_should_not_be_reversed_if_validation_fails
56 56 from = Issue.find(1)
57 57 to = Issue.find(2)
58 58
59 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'
60 62 assert !relation.save
61 63 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type
62 64 assert_equal from, relation.issue_from
63 65 assert_equal to, relation.issue_to
64 66 end
65 67
66 68 def test_relation_type_for
67 69 from = Issue.find(1)
68 70 to = Issue.find(2)
69 71
70 72 relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_PRECEDES
71 73 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from)
72 74 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to)
73 75 end
74 76
75 77 def test_set_issue_to_dates_without_issue_to
76 78 r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), :relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1)
77 79 assert_nil r.set_issue_to_dates
78 80 end
79 81
80 82 def test_set_issue_to_dates_without_issues
81 83 r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1)
82 84 assert_nil r.set_issue_to_dates
83 85 end
84 86
85 87 def test_validates_circular_dependency
86 88 IssueRelation.delete_all
87 89 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_PRECEDES)
88 90 assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_PRECEDES)
89 91 r = IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_PRECEDES)
90 92 assert !r.save
91 93 assert_not_nil r.errors[:base]
92 94 end
93 95
94 96 def test_validates_circular_dependency_on_reverse_relations
95 97 IssueRelation.delete_all
96 98 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_BLOCKS)
97 99 assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_BLOCKED)
98 100 r = IssueRelation.new(:issue_from => Issue.find(2), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_BLOCKED)
99 101 assert !r.save
100 102 assert_not_nil r.errors[:base]
101 103 end
102 104 end
General Comments 0
You need to be logged in to leave comments. Login now