annotate .svn/pristine/f3/f3d17e99db34b327082293cae60c040f3e916800.svn-base @ 1296:038ba2d95de8 redmine-2.2

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