1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
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.
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.
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.
18 require File.dirname(__FILE__) + '/../test_helper'
20 class ProjectTest < Test::Unit::TestCase
24 @ecookbook = Project.find(1)
25 @ecookbook_sub1 = Project.find(3)
29 assert_kind_of Project, @ecookbook
30 assert_equal "eCookbook", @ecookbook.name
34 assert_equal "eCookbook", @ecookbook.name
35 @ecookbook.name = "eCook"
36 assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
38 assert_equal "eCook", @ecookbook.name
43 assert !@ecookbook.save
44 assert_equal 1, @ecookbook.errors.count
45 assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
48 def test_public_projects
49 public_projects = Project.find(:all, :conditions => ["is_public=?", true])
50 assert_equal 3, public_projects.length
51 assert_equal true, public_projects[0].is_public?
55 user = @ecookbook.members.first.user
59 assert !@ecookbook.active?
60 assert !user.projects.include?(@ecookbook)
61 # Subproject are also archived
62 assert !@ecookbook.children.empty?
63 assert @ecookbook.active_children.empty?
67 user = @ecookbook.members.first.user
69 # A subproject of an archived project can not be unarchived
70 assert !@ecookbook_sub1.unarchive
73 assert @ecookbook.unarchive
75 assert @ecookbook.active?
76 assert user.projects.include?(@ecookbook)
77 # Subproject can now be unarchived
78 @ecookbook_sub1.reload
79 assert @ecookbook_sub1.unarchive
84 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
87 def test_subproject_ok
89 sub.parent = @ecookbook
91 assert_equal @ecookbook.id, sub.parent.id
93 assert_equal 3, @ecookbook.children.size
96 def test_subproject_invalid
98 sub.parent = @ecookbook_sub1
102 def test_subproject_invalid_2
104 sub.parent = Project.find(2)