Added 'Bulk edit' functionality.
[gitredmine.git] / test / unit / project_test.rb
blob14612d306bdec2aaef7ceb1c2e09f1f4c0eeb474
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.
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.
18 require File.dirname(__FILE__) + '/../test_helper'
20 class ProjectTest < Test::Unit::TestCase
21   fixtures :projects
23   def setup
24     @ecookbook = Project.find(1)
25     @ecookbook_sub1 = Project.find(3)
26   end
27   
28   def test_truth
29     assert_kind_of Project, @ecookbook
30     assert_equal "eCookbook", @ecookbook.name
31   end
32   
33   def test_update
34     assert_equal "eCookbook", @ecookbook.name
35     @ecookbook.name = "eCook"
36     assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
37     @ecookbook.reload
38     assert_equal "eCook", @ecookbook.name
39   end
40   
41   def test_validate
42     @ecookbook.name = ""
43     assert !@ecookbook.save
44     assert_equal 1, @ecookbook.errors.count
45     assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
46   end
47   
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?
52   end
53   
54   def test_archive
55     user = @ecookbook.members.first.user
56     @ecookbook.archive
57     @ecookbook.reload
58     
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?
64   end
65   
66   def test_unarchive
67     user = @ecookbook.members.first.user
68     @ecookbook.archive
69     # A subproject of an archived project can not be unarchived
70     assert !@ecookbook_sub1.unarchive
71     
72     # Unarchive project
73     assert @ecookbook.unarchive
74     @ecookbook.reload
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
80   end
81   
82   def test_destroy
83     @ecookbook.destroy
84     assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
85   end
86   
87   def test_subproject_ok
88     sub = Project.find(2)
89     sub.parent = @ecookbook
90     assert sub.save
91     assert_equal @ecookbook.id, sub.parent.id
92     @ecookbook.reload
93     assert_equal 3, @ecookbook.children.size
94   end
95   
96   def test_subproject_invalid
97     sub = Project.find(2)
98     sub.parent = @ecookbook_sub1
99     assert !sub.save
100   end
101   
102   def test_subproject_invalid_2
103     sub = @ecookbook
104     sub.parent = Project.find(2)
105     assert !sub.save
106   end