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