Chris@1115: # encoding: utf-8 Chris@1115: # Chris@1115: # Redmine - project management software Chris@1494: # Copyright (C) 2006-2014 Jean-Philippe Lang Chris@1115: # Chris@1115: # This program is free software; you can redistribute it and/or Chris@1115: # modify it under the terms of the GNU General Public License Chris@1115: # as published by the Free Software Foundation; either version 2 Chris@1115: # of the License, or (at your option) any later version. Chris@1115: # Chris@1115: # This program is distributed in the hope that it will be useful, Chris@1115: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1115: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1115: # GNU General Public License for more details. Chris@1115: # Chris@1115: # You should have received a copy of the GNU General Public License Chris@1115: # along with this program; if not, write to the Free Software Chris@1115: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1115: Chris@119: require File.expand_path('../../test_helper', __FILE__) Chris@0: Chris@0: class BoardTest < ActiveSupport::TestCase Chris@119: fixtures :projects, :boards, :messages, :attachments, :watchers Chris@0: Chris@1115: include Redmine::I18n Chris@1115: Chris@0: def setup Chris@0: @project = Project.find(1) Chris@0: end Chris@909: Chris@0: def test_create Chris@0: board = Board.new(:project => @project, :name => 'Test board', :description => 'Test board description') Chris@0: assert board.save Chris@0: board.reload Chris@0: assert_equal 'Test board', board.name Chris@0: assert_equal 'Test board description', board.description Chris@0: assert_equal @project, board.project Chris@0: assert_equal 0, board.topics_count Chris@0: assert_equal 0, board.messages_count Chris@0: assert_nil board.last_message Chris@0: # last position Chris@0: assert_equal @project.boards.size, board.position Chris@0: end Chris@909: Chris@1115: def test_parent_should_be_in_same_project Chris@1115: set_language_if_valid 'en' Chris@1115: board = Board.new(:project_id => 3, :name => 'Test', :description => 'Test', :parent_id => 1) Chris@1115: assert !board.save Chris@1115: assert_include "Parent forum is invalid", board.errors.full_messages Chris@1115: end Chris@1115: Chris@1115: def test_valid_parents_should_not_include_self_nor_a_descendant Chris@1115: board1 = Board.generate!(:project_id => 3) Chris@1115: board2 = Board.generate!(:project_id => 3, :parent => board1) Chris@1115: board3 = Board.generate!(:project_id => 3, :parent => board2) Chris@1115: board4 = Board.generate!(:project_id => 3) Chris@1115: Chris@1115: assert_equal [board4], board1.reload.valid_parents.sort_by(&:id) Chris@1115: assert_equal [board1, board4], board2.reload.valid_parents.sort_by(&:id) Chris@1115: assert_equal [board1, board2, board4], board3.reload.valid_parents.sort_by(&:id) Chris@1115: assert_equal [board1, board2, board3], board4.reload.valid_parents.sort_by(&:id) Chris@1115: end Chris@1115: Chris@1115: def test_position_should_be_assigned_with_parent_scope Chris@1115: parent1 = Board.generate!(:project_id => 3) Chris@1115: parent2 = Board.generate!(:project_id => 3) Chris@1115: child1 = Board.generate!(:project_id => 3, :parent => parent1) Chris@1115: child2 = Board.generate!(:project_id => 3, :parent => parent1) Chris@1115: Chris@1115: assert_equal 1, parent1.reload.position Chris@1115: assert_equal 1, child1.reload.position Chris@1115: assert_equal 2, child2.reload.position Chris@1115: assert_equal 2, parent2.reload.position Chris@1115: end Chris@1115: Chris@1115: def test_board_tree_should_yield_boards_with_level Chris@1115: parent1 = Board.generate!(:project_id => 3) Chris@1115: parent2 = Board.generate!(:project_id => 3) Chris@1115: child1 = Board.generate!(:project_id => 3, :parent => parent1) Chris@1115: child2 = Board.generate!(:project_id => 3, :parent => parent1) Chris@1115: child3 = Board.generate!(:project_id => 3, :parent => child1) Chris@1115: Chris@1115: tree = Board.board_tree(Project.find(3).boards) Chris@1115: Chris@1115: assert_equal [ Chris@1115: [parent1, 0], Chris@1115: [child1, 1], Chris@1115: [child3, 2], Chris@1115: [child2, 1], Chris@1115: [parent2, 0] Chris@1115: ], tree Chris@1115: end Chris@1115: Chris@0: def test_destroy Chris@0: board = Board.find(1) Chris@119: assert_difference 'Message.count', -6 do Chris@119: assert_difference 'Attachment.count', -1 do Chris@119: assert_difference 'Watcher.count', -1 do Chris@119: assert board.destroy Chris@119: end Chris@119: end Chris@119: end Chris@1464: assert_equal 0, Message.where(:board_id => 1).count Chris@0: end Chris@1115: Chris@1115: def test_destroy_should_nullify_children Chris@1115: parent = Board.generate!(:project => @project) Chris@1115: child = Board.generate!(:project => @project, :parent => parent) Chris@1115: assert_equal parent, child.parent Chris@1115: Chris@1115: assert parent.destroy Chris@1115: child.reload Chris@1115: assert_nil child.parent Chris@1115: assert_nil child.parent_id Chris@1115: end Chris@0: end