GITSCM: Tweaked git scm view layout
[gitredmine.git] / test / unit / project_test.rb
bloba8cf46e4f0a30b0d098bfda9015d624b39bbf8dc
1 # redMine - project management software\r
2 # Copyright (C) 2006-2007  Jean-Philippe Lang\r
3 #\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
8 \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
13 \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
23   def setup\r
24     @ecookbook = Project.find(1)\r
25     @ecookbook_sub1 = Project.find(3)\r
26   end\r
27   \r
28   def test_truth\r
29     assert_kind_of Project, @ecookbook\r
30     assert_equal "eCookbook", @ecookbook.name\r
31   end\r
32   \r
33   def test_update\r
34     assert_equal "eCookbook", @ecookbook.name\r
35     @ecookbook.name = "eCook"\r
36     assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")\r
37     @ecookbook.reload\r
38     assert_equal "eCook", @ecookbook.name\r
39   end\r
40   \r
41   def test_validate\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
46   end\r
47   \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
52   end\r
53   \r
54   def test_archive\r
55     user = @ecookbook.members.first.user\r
56     @ecookbook.archive\r
57     @ecookbook.reload\r
58     \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
64   end\r
65   \r
66   def test_unarchive\r
67     user = @ecookbook.members.first.user\r
68     @ecookbook.archive\r
69     # A subproject of an archived project can not be unarchived\r
70     assert !@ecookbook_sub1.unarchive\r
71     \r
72     # Unarchive project\r
73     assert @ecookbook.unarchive\r
74     @ecookbook.reload\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
80   end\r
81   \r
82   def test_destroy\r
83     @ecookbook.destroy\r
84     assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }\r
85   end\r
86   \r
87   def test_subproject_ok\r
88     sub = Project.find(2)\r
89     sub.parent = @ecookbook\r
90     assert sub.save\r
91     assert_equal @ecookbook.id, sub.parent.id\r
92     @ecookbook.reload\r
93     assert_equal 3, @ecookbook.children.size\r
94   end\r
95   \r
96   def test_subproject_invalid\r
97     sub = Project.find(2)\r
98     sub.parent = @ecookbook_sub1\r
99     assert !sub.save\r
100   end\r
101   \r
102   def test_subproject_invalid_2\r
103     sub = @ecookbook\r
104     sub.parent = Project.find(2)\r
105     assert !sub.save\r
106   end\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
112     \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
115   end\r
116 end\r