##// END OF EJS Templates
Fixes test broken by r1610....
Jean-Philippe Lang -
r1602:22558f77094d
parent child
Show More
@@ -1,132 +1,133
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class ProjectTest < Test::Unit::TestCase
21 21 fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, :users, :members, :roles, :projects_trackers, :trackers, :boards
22 22
23 23 def setup
24 24 @ecookbook = Project.find(1)
25 25 @ecookbook_sub1 = Project.find(3)
26 26 end
27 27
28 28 def test_truth
29 29 assert_kind_of Project, @ecookbook
30 30 assert_equal "eCookbook", @ecookbook.name
31 31 end
32 32
33 33 def test_update
34 34 assert_equal "eCookbook", @ecookbook.name
35 35 @ecookbook.name = "eCook"
36 36 assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
37 37 @ecookbook.reload
38 38 assert_equal "eCook", @ecookbook.name
39 39 end
40 40
41 41 def test_validate
42 42 @ecookbook.name = ""
43 43 assert !@ecookbook.save
44 44 assert_equal 1, @ecookbook.errors.count
45 45 assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
46 46 end
47 47
48 48 def test_public_projects
49 49 public_projects = Project.find(:all, :conditions => ["is_public=?", true])
50 50 assert_equal 3, public_projects.length
51 51 assert_equal true, public_projects[0].is_public?
52 52 end
53 53
54 54 def test_archive
55 55 user = @ecookbook.members.first.user
56 56 @ecookbook.archive
57 57 @ecookbook.reload
58 58
59 59 assert !@ecookbook.active?
60 60 assert !user.projects.include?(@ecookbook)
61 61 # Subproject are also archived
62 62 assert !@ecookbook.children.empty?
63 63 assert @ecookbook.active_children.empty?
64 64 end
65 65
66 66 def test_unarchive
67 67 user = @ecookbook.members.first.user
68 68 @ecookbook.archive
69 69 # A subproject of an archived project can not be unarchived
70 70 assert !@ecookbook_sub1.unarchive
71 71
72 72 # Unarchive project
73 73 assert @ecookbook.unarchive
74 74 @ecookbook.reload
75 75 assert @ecookbook.active?
76 76 assert user.projects.include?(@ecookbook)
77 77 # Subproject can now be unarchived
78 78 @ecookbook_sub1.reload
79 79 assert @ecookbook_sub1.unarchive
80 80 end
81 81
82 82 def test_destroy
83 83 # 2 active members
84 84 assert_equal 2, @ecookbook.members.size
85 85 # and 1 is locked
86 86 assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size
87 87 # some boards
88 88 assert @ecookbook.boards.any?
89 89
90 90 @ecookbook.destroy
91 91 # make sure that the project non longer exists
92 92 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
93 93 # make sure related data was removed
94 94 assert Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
95 95 assert Board.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
96 96 end
97 97
98 98 def test_subproject_ok
99 99 sub = Project.find(2)
100 100 sub.parent = @ecookbook
101 101 assert sub.save
102 102 assert_equal @ecookbook.id, sub.parent.id
103 103 @ecookbook.reload
104 104 assert_equal 4, @ecookbook.children.size
105 105 end
106 106
107 107 def test_subproject_invalid
108 108 sub = Project.find(2)
109 109 sub.parent = @ecookbook_sub1
110 110 assert !sub.save
111 111 end
112 112
113 113 def test_subproject_invalid_2
114 114 sub = @ecookbook
115 115 sub.parent = Project.find(2)
116 116 assert !sub.save
117 117 end
118 118
119 119 def test_rolled_up_trackers
120 120 parent = Project.find(1)
121 parent.trackers = Tracker.find([1,2])
121 122 child = parent.children.find(3)
122 123
123 124 assert_equal [1, 2], parent.tracker_ids
124 125 assert_equal [2, 3], child.tracker_ids
125 126
126 127 assert_kind_of Tracker, parent.rolled_up_trackers.first
127 128 assert_equal Tracker.find(1), parent.rolled_up_trackers.first
128 129
129 130 assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id)
130 131 assert_equal [2, 3], child.rolled_up_trackers.collect(&:id)
131 132 end
132 133 end
General Comments 0
You need to be logged in to leave comments. Login now