annotate test/unit/board_test.rb @ 1516:b450a9d58aed redmine-2.4

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