annotate .svn/pristine/70/70f9bc29bb52483c05a4b14c83b2954dccfb5538.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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