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