Mercurial > hg > soundsoftware-site
comparison .svn/pristine/fa/fa1ed3a060024a3911e7dcef012f4c68185e0ea3.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # encoding: utf-8 | |
2 # | |
3 # Redmine - project management software | |
4 # Copyright (C) 2006-2013 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 | |
20 require File.expand_path('../../test_helper', __FILE__) | |
21 | |
22 class BoardTest < ActiveSupport::TestCase | |
23 fixtures :projects, :boards, :messages, :attachments, :watchers | |
24 | |
25 include Redmine::I18n | |
26 | |
27 def setup | |
28 @project = Project.find(1) | |
29 end | |
30 | |
31 def test_create | |
32 board = Board.new(:project => @project, :name => 'Test board', :description => 'Test board description') | |
33 assert board.save | |
34 board.reload | |
35 assert_equal 'Test board', board.name | |
36 assert_equal 'Test board description', board.description | |
37 assert_equal @project, board.project | |
38 assert_equal 0, board.topics_count | |
39 assert_equal 0, board.messages_count | |
40 assert_nil board.last_message | |
41 # last position | |
42 assert_equal @project.boards.size, board.position | |
43 end | |
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 | |
94 def test_destroy | |
95 board = Board.find(1) | |
96 assert_difference 'Message.count', -6 do | |
97 assert_difference 'Attachment.count', -1 do | |
98 assert_difference 'Watcher.count', -1 do | |
99 assert board.destroy | |
100 end | |
101 end | |
102 end | |
103 assert_equal 0, Message.count(:conditions => {:board_id => 1}) | |
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 | |
116 end |