1 # redMine - project management software
\r
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
\r
4 # This program is free software; you can redistribute it and/or
\r
5 # modify it under the terms of the GNU General Public License
\r
6 # as published by the Free Software Foundation; either version 2
\r
7 # of the License, or (at your option) any later version.
\r
9 # This program is distributed in the hope that it will be useful,
\r
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 # GNU General Public License for more details.
\r
14 # You should have received a copy of the GNU General Public License
\r
15 # along with this program; if not, write to the Free Software
\r
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
18 require File.dirname(__FILE__) + '/../test_helper'
\r
20 class ProjectTest < Test::Unit::TestCase
\r
21 fixtures :projects, :issues, :issue_statuses, :journals, :journal_details
\r
24 @ecookbook = Project.find(1)
\r
25 @ecookbook_sub1 = Project.find(3)
\r
29 assert_kind_of Project, @ecookbook
\r
30 assert_equal "eCookbook", @ecookbook.name
\r
34 assert_equal "eCookbook", @ecookbook.name
\r
35 @ecookbook.name = "eCook"
\r
36 assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
\r
38 assert_equal "eCook", @ecookbook.name
\r
42 @ecookbook.name = ""
\r
43 assert !@ecookbook.save
\r
44 assert_equal 1, @ecookbook.errors.count
\r
45 assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
\r
48 def test_public_projects
\r
49 public_projects = Project.find(:all, :conditions => ["is_public=?", true])
\r
50 assert_equal 3, public_projects.length
\r
51 assert_equal true, public_projects[0].is_public?
\r
55 user = @ecookbook.members.first.user
\r
59 assert !@ecookbook.active?
\r
60 assert !user.projects.include?(@ecookbook)
\r
61 # Subproject are also archived
\r
62 assert !@ecookbook.children.empty?
\r
63 assert @ecookbook.active_children.empty?
\r
67 user = @ecookbook.members.first.user
\r
69 # A subproject of an archived project can not be unarchived
\r
70 assert !@ecookbook_sub1.unarchive
\r
73 assert @ecookbook.unarchive
\r
75 assert @ecookbook.active?
\r
76 assert user.projects.include?(@ecookbook)
\r
77 # Subproject can now be unarchived
\r
78 @ecookbook_sub1.reload
\r
79 assert @ecookbook_sub1.unarchive
\r
84 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
\r
87 def test_subproject_ok
\r
88 sub = Project.find(2)
\r
89 sub.parent = @ecookbook
\r
91 assert_equal @ecookbook.id, sub.parent.id
\r
93 assert_equal 3, @ecookbook.children.size
\r
96 def test_subproject_invalid
\r
97 sub = Project.find(2)
\r
98 sub.parent = @ecookbook_sub1
\r
102 def test_subproject_invalid_2
\r
104 sub.parent = Project.find(2)
\r
108 def test_issues_status_changes
\r
109 journals = @ecookbook.issues_status_changes 3.days.ago.to_date, Date.today
\r
110 assert_equal 1, journals.size
\r
111 assert_kind_of Journal, journals.first
\r
113 journals = @ecookbook.issues_status_changes 30.days.ago.to_date, 10.days.ago.to_date
\r
114 assert_equal 0, journals.size
\r