##// END OF EJS Templates
use set_language_if_valid 'en' at test_parent_should_be_in_same_project at unit board test...
Toshi MARUYAMA -
r10271:455738cbe982
parent child
Show More
@@ -1,113 +1,116
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2012 Jean-Philippe Lang
4 # Copyright (C) 2006-2012 Jean-Philippe Lang
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 require File.expand_path('../../test_helper', __FILE__)
20 require File.expand_path('../../test_helper', __FILE__)
21
21
22 class BoardTest < ActiveSupport::TestCase
22 class BoardTest < ActiveSupport::TestCase
23 fixtures :projects, :boards, :messages, :attachments, :watchers
23 fixtures :projects, :boards, :messages, :attachments, :watchers
24
24
25 include Redmine::I18n
26
25 def setup
27 def setup
26 @project = Project.find(1)
28 @project = Project.find(1)
27 end
29 end
28
30
29 def test_create
31 def test_create
30 board = Board.new(:project => @project, :name => 'Test board', :description => 'Test board description')
32 board = Board.new(:project => @project, :name => 'Test board', :description => 'Test board description')
31 assert board.save
33 assert board.save
32 board.reload
34 board.reload
33 assert_equal 'Test board', board.name
35 assert_equal 'Test board', board.name
34 assert_equal 'Test board description', board.description
36 assert_equal 'Test board description', board.description
35 assert_equal @project, board.project
37 assert_equal @project, board.project
36 assert_equal 0, board.topics_count
38 assert_equal 0, board.topics_count
37 assert_equal 0, board.messages_count
39 assert_equal 0, board.messages_count
38 assert_nil board.last_message
40 assert_nil board.last_message
39 # last position
41 # last position
40 assert_equal @project.boards.size, board.position
42 assert_equal @project.boards.size, board.position
41 end
43 end
42
44
43 def test_parent_should_be_in_same_project
45 def test_parent_should_be_in_same_project
46 set_language_if_valid 'en'
44 board = Board.new(:project_id => 3, :name => 'Test', :description => 'Test', :parent_id => 1)
47 board = Board.new(:project_id => 3, :name => 'Test', :description => 'Test', :parent_id => 1)
45 assert !board.save
48 assert !board.save
46 assert_include "Parent forum is invalid", board.errors.full_messages
49 assert_include "Parent forum is invalid", board.errors.full_messages
47 end
50 end
48
51
49 def test_valid_parents_should_not_include_self_nor_a_descendant
52 def test_valid_parents_should_not_include_self_nor_a_descendant
50 board1 = Board.generate!(:project_id => 3)
53 board1 = Board.generate!(:project_id => 3)
51 board2 = Board.generate!(:project_id => 3, :parent => board1)
54 board2 = Board.generate!(:project_id => 3, :parent => board1)
52 board3 = Board.generate!(:project_id => 3, :parent => board2)
55 board3 = Board.generate!(:project_id => 3, :parent => board2)
53 board4 = Board.generate!(:project_id => 3)
56 board4 = Board.generate!(:project_id => 3)
54
57
55 assert_equal [board4], board1.reload.valid_parents.sort_by(&:id)
58 assert_equal [board4], board1.reload.valid_parents.sort_by(&:id)
56 assert_equal [board1, board4], board2.reload.valid_parents.sort_by(&:id)
59 assert_equal [board1, board4], board2.reload.valid_parents.sort_by(&:id)
57 assert_equal [board1, board2, board4], board3.reload.valid_parents.sort_by(&:id)
60 assert_equal [board1, board2, board4], board3.reload.valid_parents.sort_by(&:id)
58 assert_equal [board1, board2, board3], board4.reload.valid_parents.sort_by(&:id)
61 assert_equal [board1, board2, board3], board4.reload.valid_parents.sort_by(&:id)
59 end
62 end
60
63
61 def test_position_should_be_assigned_with_parent_scope
64 def test_position_should_be_assigned_with_parent_scope
62 parent1 = Board.generate!(:project_id => 3)
65 parent1 = Board.generate!(:project_id => 3)
63 parent2 = Board.generate!(:project_id => 3)
66 parent2 = Board.generate!(:project_id => 3)
64 child1 = Board.generate!(:project_id => 3, :parent => parent1)
67 child1 = Board.generate!(:project_id => 3, :parent => parent1)
65 child2 = Board.generate!(:project_id => 3, :parent => parent1)
68 child2 = Board.generate!(:project_id => 3, :parent => parent1)
66
69
67 assert_equal 1, parent1.reload.position
70 assert_equal 1, parent1.reload.position
68 assert_equal 1, child1.reload.position
71 assert_equal 1, child1.reload.position
69 assert_equal 2, child2.reload.position
72 assert_equal 2, child2.reload.position
70 assert_equal 2, parent2.reload.position
73 assert_equal 2, parent2.reload.position
71 end
74 end
72
75
73 def test_board_tree_should_yield_boards_with_level
76 def test_board_tree_should_yield_boards_with_level
74 parent1 = Board.generate!(:project_id => 3)
77 parent1 = Board.generate!(:project_id => 3)
75 parent2 = Board.generate!(:project_id => 3)
78 parent2 = Board.generate!(:project_id => 3)
76 child1 = Board.generate!(:project_id => 3, :parent => parent1)
79 child1 = Board.generate!(:project_id => 3, :parent => parent1)
77 child2 = Board.generate!(:project_id => 3, :parent => parent1)
80 child2 = Board.generate!(:project_id => 3, :parent => parent1)
78 child3 = Board.generate!(:project_id => 3, :parent => child1)
81 child3 = Board.generate!(:project_id => 3, :parent => child1)
79
82
80 tree = Board.board_tree(Project.find(3).boards)
83 tree = Board.board_tree(Project.find(3).boards)
81
84
82 assert_equal [
85 assert_equal [
83 [parent1, 0],
86 [parent1, 0],
84 [child1, 1],
87 [child1, 1],
85 [child3, 2],
88 [child3, 2],
86 [child2, 1],
89 [child2, 1],
87 [parent2, 0]
90 [parent2, 0]
88 ], tree
91 ], tree
89 end
92 end
90
93
91 def test_destroy
94 def test_destroy
92 board = Board.find(1)
95 board = Board.find(1)
93 assert_difference 'Message.count', -6 do
96 assert_difference 'Message.count', -6 do
94 assert_difference 'Attachment.count', -1 do
97 assert_difference 'Attachment.count', -1 do
95 assert_difference 'Watcher.count', -1 do
98 assert_difference 'Watcher.count', -1 do
96 assert board.destroy
99 assert board.destroy
97 end
100 end
98 end
101 end
99 end
102 end
100 assert_equal 0, Message.count(:conditions => {:board_id => 1})
103 assert_equal 0, Message.count(:conditions => {:board_id => 1})
101 end
104 end
102
105
103 def test_destroy_should_nullify_children
106 def test_destroy_should_nullify_children
104 parent = Board.generate!(:project => @project)
107 parent = Board.generate!(:project => @project)
105 child = Board.generate!(:project => @project, :parent => parent)
108 child = Board.generate!(:project => @project, :parent => parent)
106 assert_equal parent, child.parent
109 assert_equal parent, child.parent
107
110
108 assert parent.destroy
111 assert parent.destroy
109 child.reload
112 child.reload
110 assert_nil child.parent
113 assert_nil child.parent
111 assert_nil child.parent_id
114 assert_nil child.parent_id
112 end
115 end
113 end
116 end
General Comments 0
You need to be logged in to leave comments. Login now