Chris@0
|
1 # Redmine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@0
|
18 require File.dirname(__FILE__) + '/../test_helper'
|
Chris@0
|
19
|
Chris@0
|
20 class ProjectNestedSetTest < ActiveSupport::TestCase
|
Chris@0
|
21
|
Chris@0
|
22 def setup
|
Chris@0
|
23 Project.delete_all
|
Chris@0
|
24 end
|
Chris@0
|
25
|
Chris@0
|
26 def test_destroy_root_and_chldren_should_not_mess_up_the_tree
|
Chris@0
|
27 a = Project.create!(:name => 'Project A', :identifier => 'projecta')
|
Chris@0
|
28 a1 = Project.create!(:name => 'Project A1', :identifier => 'projecta1')
|
Chris@0
|
29 a2 = Project.create!(:name => 'Project A2', :identifier => 'projecta2')
|
Chris@0
|
30 a1.set_parent!(a)
|
Chris@0
|
31 a2.set_parent!(a)
|
Chris@0
|
32 b = Project.create!(:name => 'Project B', :identifier => 'projectb')
|
Chris@0
|
33 b1 = Project.create!(:name => 'Project B1', :identifier => 'projectb1')
|
Chris@0
|
34 b1.set_parent!(b)
|
Chris@0
|
35
|
Chris@0
|
36 a.reload
|
Chris@0
|
37 a1.reload
|
Chris@0
|
38 a2.reload
|
Chris@0
|
39 b.reload
|
Chris@0
|
40 b1.reload
|
Chris@0
|
41
|
Chris@0
|
42 assert_equal [nil, 1, 6], [a.parent_id, a.lft, a.rgt]
|
Chris@0
|
43 assert_equal [a.id, 2, 3], [a1.parent_id, a1.lft, a1.rgt]
|
Chris@0
|
44 assert_equal [a.id, 4, 5], [a2.parent_id, a2.lft, a2.rgt]
|
Chris@0
|
45 assert_equal [nil, 7, 10], [b.parent_id, b.lft, b.rgt]
|
Chris@0
|
46 assert_equal [b.id, 8, 9], [b1.parent_id, b1.lft, b1.rgt]
|
Chris@0
|
47
|
Chris@0
|
48 assert_difference 'Project.count', -3 do
|
Chris@0
|
49 a.destroy
|
Chris@0
|
50 end
|
Chris@0
|
51
|
Chris@0
|
52 b.reload
|
Chris@0
|
53 b1.reload
|
Chris@0
|
54
|
Chris@0
|
55 assert_equal [nil, 1, 4], [b.parent_id, b.lft, b.rgt]
|
Chris@0
|
56 assert_equal [b.id, 2, 3], [b1.parent_id, b1.lft, b1.rgt]
|
Chris@0
|
57 end
|
Chris@0
|
58 end |