Mercurial > hg > soundsoftware-site
comparison .svn/pristine/73/7324bdf575eb0516e737af169c50f43705081a91.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
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 | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../test_helper', __FILE__) | |
19 | |
20 class IssueRelationTest < ActiveSupport::TestCase | |
21 fixtures :projects, | |
22 :users, | |
23 :roles, | |
24 :members, | |
25 :member_roles, | |
26 :issues, | |
27 :issue_statuses, | |
28 :issue_relations, | |
29 :enabled_modules, | |
30 :enumerations, | |
31 :trackers | |
32 | |
33 include Redmine::I18n | |
34 | |
35 def test_create | |
36 from = Issue.find(1) | |
37 to = Issue.find(2) | |
38 | |
39 relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
40 :relation_type => IssueRelation::TYPE_PRECEDES | |
41 assert relation.save | |
42 relation.reload | |
43 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type | |
44 assert_equal from, relation.issue_from | |
45 assert_equal to, relation.issue_to | |
46 end | |
47 | |
48 def test_create_minimum | |
49 relation = IssueRelation.new :issue_from => Issue.find(1), :issue_to => Issue.find(2) | |
50 assert relation.save | |
51 assert_equal IssueRelation::TYPE_RELATES, relation.relation_type | |
52 end | |
53 | |
54 def test_follows_relation_should_be_reversed | |
55 from = Issue.find(1) | |
56 to = Issue.find(2) | |
57 | |
58 relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
59 :relation_type => IssueRelation::TYPE_FOLLOWS | |
60 assert relation.save | |
61 relation.reload | |
62 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type | |
63 assert_equal to, relation.issue_from | |
64 assert_equal from, relation.issue_to | |
65 end | |
66 | |
67 def test_follows_relation_should_not_be_reversed_if_validation_fails | |
68 from = Issue.find(1) | |
69 to = Issue.find(2) | |
70 | |
71 relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
72 :relation_type => IssueRelation::TYPE_FOLLOWS, | |
73 :delay => 'xx' | |
74 assert !relation.save | |
75 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type | |
76 assert_equal from, relation.issue_from | |
77 assert_equal to, relation.issue_to | |
78 end | |
79 | |
80 def test_relation_type_for | |
81 from = Issue.find(1) | |
82 to = Issue.find(2) | |
83 | |
84 relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
85 :relation_type => IssueRelation::TYPE_PRECEDES | |
86 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from) | |
87 assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to) | |
88 end | |
89 | |
90 def test_set_issue_to_dates_without_issue_to | |
91 r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), | |
92 :relation_type => IssueRelation::TYPE_PRECEDES, | |
93 :delay => 1) | |
94 assert_nil r.set_issue_to_dates | |
95 end | |
96 | |
97 def test_set_issue_to_dates_without_issues | |
98 r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) | |
99 assert_nil r.set_issue_to_dates | |
100 end | |
101 | |
102 def test_validates_circular_dependency | |
103 IssueRelation.delete_all | |
104 assert IssueRelation.create!( | |
105 :issue_from => Issue.find(1), :issue_to => Issue.find(2), | |
106 :relation_type => IssueRelation::TYPE_PRECEDES | |
107 ) | |
108 assert IssueRelation.create!( | |
109 :issue_from => Issue.find(2), :issue_to => Issue.find(3), | |
110 :relation_type => IssueRelation::TYPE_PRECEDES | |
111 ) | |
112 r = IssueRelation.new( | |
113 :issue_from => Issue.find(3), :issue_to => Issue.find(1), | |
114 :relation_type => IssueRelation::TYPE_PRECEDES | |
115 ) | |
116 assert !r.save | |
117 assert_not_nil r.errors[:base] | |
118 end | |
119 | |
120 def test_validates_circular_dependency_of_subtask | |
121 set_language_if_valid 'en' | |
122 issue1 = Issue.generate! | |
123 issue2 = Issue.generate! | |
124 IssueRelation.create!( | |
125 :issue_from => issue1, :issue_to => issue2, | |
126 :relation_type => IssueRelation::TYPE_PRECEDES | |
127 ) | |
128 child = Issue.generate!(:parent_issue_id => issue2.id) | |
129 issue1.reload | |
130 child.reload | |
131 | |
132 r = IssueRelation.new( | |
133 :issue_from => child, :issue_to => issue1, | |
134 :relation_type => IssueRelation::TYPE_PRECEDES | |
135 ) | |
136 assert !r.save | |
137 assert_include 'This relation would create a circular dependency', r.errors.full_messages | |
138 end | |
139 | |
140 def test_subtasks_should_allow_precedes_relation | |
141 parent = Issue.generate! | |
142 child1 = Issue.generate!(:parent_issue_id => parent.id) | |
143 child2 = Issue.generate!(:parent_issue_id => parent.id) | |
144 | |
145 r = IssueRelation.new( | |
146 :issue_from => child1, :issue_to => child2, | |
147 :relation_type => IssueRelation::TYPE_PRECEDES | |
148 ) | |
149 assert r.valid? | |
150 assert r.save | |
151 end | |
152 | |
153 def test_validates_circular_dependency_on_reverse_relations | |
154 IssueRelation.delete_all | |
155 assert IssueRelation.create!( | |
156 :issue_from => Issue.find(1), :issue_to => Issue.find(3), | |
157 :relation_type => IssueRelation::TYPE_BLOCKS | |
158 ) | |
159 assert IssueRelation.create!( | |
160 :issue_from => Issue.find(1), :issue_to => Issue.find(2), | |
161 :relation_type => IssueRelation::TYPE_BLOCKED | |
162 ) | |
163 r = IssueRelation.new( | |
164 :issue_from => Issue.find(2), :issue_to => Issue.find(1), | |
165 :relation_type => IssueRelation::TYPE_BLOCKED | |
166 ) | |
167 assert !r.save | |
168 assert_not_nil r.errors[:base] | |
169 end | |
170 end |