comparison test/unit/board_test.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # encoding: utf-8
2 #
3 # Redmine - project management software
4 # Copyright (C) 2006-2012 Jean-Philippe Lang
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
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
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
1 require File.expand_path('../../test_helper', __FILE__) 20 require File.expand_path('../../test_helper', __FILE__)
2 21
3 class BoardTest < ActiveSupport::TestCase 22 class BoardTest < ActiveSupport::TestCase
4 fixtures :projects, :boards, :messages, :attachments, :watchers 23 fixtures :projects, :boards, :messages, :attachments, :watchers
24
25 include Redmine::I18n
5 26
6 def setup 27 def setup
7 @project = Project.find(1) 28 @project = Project.find(1)
8 end 29 end
9 30
19 assert_nil board.last_message 40 assert_nil board.last_message
20 # last position 41 # last position
21 assert_equal @project.boards.size, board.position 42 assert_equal @project.boards.size, board.position
22 end 43 end
23 44
45 def test_parent_should_be_in_same_project
46 set_language_if_valid 'en'
47 board = Board.new(:project_id => 3, :name => 'Test', :description => 'Test', :parent_id => 1)
48 assert !board.save
49 assert_include "Parent forum is invalid", board.errors.full_messages
50 end
51
52 def test_valid_parents_should_not_include_self_nor_a_descendant
53 board1 = Board.generate!(:project_id => 3)
54 board2 = Board.generate!(:project_id => 3, :parent => board1)
55 board3 = Board.generate!(:project_id => 3, :parent => board2)
56 board4 = Board.generate!(:project_id => 3)
57
58 assert_equal [board4], board1.reload.valid_parents.sort_by(&:id)
59 assert_equal [board1, board4], board2.reload.valid_parents.sort_by(&:id)
60 assert_equal [board1, board2, board4], board3.reload.valid_parents.sort_by(&:id)
61 assert_equal [board1, board2, board3], board4.reload.valid_parents.sort_by(&:id)
62 end
63
64 def test_position_should_be_assigned_with_parent_scope
65 parent1 = Board.generate!(:project_id => 3)
66 parent2 = Board.generate!(:project_id => 3)
67 child1 = Board.generate!(:project_id => 3, :parent => parent1)
68 child2 = Board.generate!(:project_id => 3, :parent => parent1)
69
70 assert_equal 1, parent1.reload.position
71 assert_equal 1, child1.reload.position
72 assert_equal 2, child2.reload.position
73 assert_equal 2, parent2.reload.position
74 end
75
76 def test_board_tree_should_yield_boards_with_level
77 parent1 = Board.generate!(:project_id => 3)
78 parent2 = Board.generate!(:project_id => 3)
79 child1 = Board.generate!(:project_id => 3, :parent => parent1)
80 child2 = Board.generate!(:project_id => 3, :parent => parent1)
81 child3 = Board.generate!(:project_id => 3, :parent => child1)
82
83 tree = Board.board_tree(Project.find(3).boards)
84
85 assert_equal [
86 [parent1, 0],
87 [child1, 1],
88 [child3, 2],
89 [child2, 1],
90 [parent2, 0]
91 ], tree
92 end
93
24 def test_destroy 94 def test_destroy
25 board = Board.find(1) 95 board = Board.find(1)
26 assert_difference 'Message.count', -6 do 96 assert_difference 'Message.count', -6 do
27 assert_difference 'Attachment.count', -1 do 97 assert_difference 'Attachment.count', -1 do
28 assert_difference 'Watcher.count', -1 do 98 assert_difference 'Watcher.count', -1 do
30 end 100 end
31 end 101 end
32 end 102 end
33 assert_equal 0, Message.count(:conditions => {:board_id => 1}) 103 assert_equal 0, Message.count(:conditions => {:board_id => 1})
34 end 104 end
105
106 def test_destroy_should_nullify_children
107 parent = Board.generate!(:project => @project)
108 child = Board.generate!(:project => @project, :parent => parent)
109 assert_equal parent, child.parent
110
111 assert parent.destroy
112 child.reload
113 assert_nil child.parent
114 assert_nil child.parent_id
115 end
35 end 116 end