To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 96 / 969ebdefc951f6343723e3a0d3d0d74cbd4ee8d0.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (4.81 KB)
| 1 | 1296:038ba2d95de8 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2012 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 | def test_create |
||
| 34 | from = Issue.find(1) |
||
| 35 | to = Issue.find(2) |
||
| 36 | |||
| 37 | relation = IssueRelation.new :issue_from => from, :issue_to => to, |
||
| 38 | :relation_type => IssueRelation::TYPE_PRECEDES |
||
| 39 | assert relation.save |
||
| 40 | relation.reload |
||
| 41 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type |
||
| 42 | assert_equal from, relation.issue_from |
||
| 43 | assert_equal to, relation.issue_to |
||
| 44 | end |
||
| 45 | |||
| 46 | def test_create_minimum |
||
| 47 | relation = IssueRelation.new :issue_from => Issue.find(1), :issue_to => Issue.find(2) |
||
| 48 | assert relation.save |
||
| 49 | assert_equal IssueRelation::TYPE_RELATES, relation.relation_type |
||
| 50 | end |
||
| 51 | |||
| 52 | def test_follows_relation_should_be_reversed |
||
| 53 | from = Issue.find(1) |
||
| 54 | to = Issue.find(2) |
||
| 55 | |||
| 56 | relation = IssueRelation.new :issue_from => from, :issue_to => to, |
||
| 57 | :relation_type => IssueRelation::TYPE_FOLLOWS |
||
| 58 | assert relation.save |
||
| 59 | relation.reload |
||
| 60 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type |
||
| 61 | assert_equal to, relation.issue_from |
||
| 62 | assert_equal from, relation.issue_to |
||
| 63 | end |
||
| 64 | |||
| 65 | def test_follows_relation_should_not_be_reversed_if_validation_fails |
||
| 66 | from = Issue.find(1) |
||
| 67 | to = Issue.find(2) |
||
| 68 | |||
| 69 | relation = IssueRelation.new :issue_from => from, :issue_to => to, |
||
| 70 | :relation_type => IssueRelation::TYPE_FOLLOWS, |
||
| 71 | :delay => 'xx' |
||
| 72 | assert !relation.save |
||
| 73 | assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type |
||
| 74 | assert_equal from, relation.issue_from |
||
| 75 | assert_equal to, relation.issue_to |
||
| 76 | end |
||
| 77 | |||
| 78 | def test_relation_type_for |
||
| 79 | from = Issue.find(1) |
||
| 80 | to = Issue.find(2) |
||
| 81 | |||
| 82 | relation = IssueRelation.new :issue_from => from, :issue_to => to, |
||
| 83 | :relation_type => IssueRelation::TYPE_PRECEDES |
||
| 84 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from) |
||
| 85 | assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to) |
||
| 86 | end |
||
| 87 | |||
| 88 | def test_set_issue_to_dates_without_issue_to |
||
| 89 | r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), |
||
| 90 | :relation_type => IssueRelation::TYPE_PRECEDES, |
||
| 91 | :delay => 1) |
||
| 92 | assert_nil r.set_issue_to_dates |
||
| 93 | end |
||
| 94 | |||
| 95 | def test_set_issue_to_dates_without_issues |
||
| 96 | r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) |
||
| 97 | assert_nil r.set_issue_to_dates |
||
| 98 | end |
||
| 99 | |||
| 100 | def test_validates_circular_dependency |
||
| 101 | IssueRelation.delete_all |
||
| 102 | assert IssueRelation.create!( |
||
| 103 | :issue_from => Issue.find(1), :issue_to => Issue.find(2), |
||
| 104 | :relation_type => IssueRelation::TYPE_PRECEDES |
||
| 105 | ) |
||
| 106 | assert IssueRelation.create!( |
||
| 107 | :issue_from => Issue.find(2), :issue_to => Issue.find(3), |
||
| 108 | :relation_type => IssueRelation::TYPE_PRECEDES |
||
| 109 | ) |
||
| 110 | r = IssueRelation.new( |
||
| 111 | :issue_from => Issue.find(3), :issue_to => Issue.find(1), |
||
| 112 | :relation_type => IssueRelation::TYPE_PRECEDES |
||
| 113 | ) |
||
| 114 | assert !r.save |
||
| 115 | assert_not_nil r.errors[:base] |
||
| 116 | end |
||
| 117 | |||
| 118 | def test_validates_circular_dependency_on_reverse_relations |
||
| 119 | IssueRelation.delete_all |
||
| 120 | assert IssueRelation.create!( |
||
| 121 | :issue_from => Issue.find(1), :issue_to => Issue.find(3), |
||
| 122 | :relation_type => IssueRelation::TYPE_BLOCKS |
||
| 123 | ) |
||
| 124 | assert IssueRelation.create!( |
||
| 125 | :issue_from => Issue.find(1), :issue_to => Issue.find(2), |
||
| 126 | :relation_type => IssueRelation::TYPE_BLOCKED |
||
| 127 | ) |
||
| 128 | r = IssueRelation.new( |
||
| 129 | :issue_from => Issue.find(2), :issue_to => Issue.find(1), |
||
| 130 | :relation_type => IssueRelation::TYPE_BLOCKED |
||
| 131 | ) |
||
| 132 | assert !r.save |
||
| 133 | assert_not_nil r.errors[:base] |
||
| 134 | end |
||
| 135 | end |