annotate test/functional/boards_controller_test.rb @ 1233:ed0d04113c93 redmine-2.2-integration

Typo fix
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 13 Mar 2013 13:10:49 +0000
parents 433d4f72a19b
children 3e4c3460b6ca
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1115 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19
Chris@0 20 class BoardsControllerTest < ActionController::TestCase
Chris@0 21 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
Chris@909 22
Chris@0 23 def setup
Chris@0 24 User.current = nil
Chris@0 25 end
Chris@909 26
Chris@0 27 def test_index
Chris@0 28 get :index, :project_id => 1
Chris@0 29 assert_response :success
Chris@0 30 assert_template 'index'
Chris@0 31 assert_not_nil assigns(:boards)
Chris@0 32 assert_not_nil assigns(:project)
Chris@0 33 end
Chris@909 34
Chris@0 35 def test_index_not_found
Chris@0 36 get :index, :project_id => 97
Chris@0 37 assert_response 404
Chris@0 38 end
Chris@909 39
Chris@0 40 def test_index_should_show_messages_if_only_one_board
Chris@0 41 Project.find(1).boards.slice(1..-1).each(&:destroy)
Chris@909 42
Chris@0 43 get :index, :project_id => 1
Chris@0 44 assert_response :success
Chris@0 45 assert_template 'show'
Chris@0 46 assert_not_nil assigns(:topics)
Chris@0 47 end
Chris@909 48
Chris@0 49 def test_show
Chris@0 50 get :show, :project_id => 1, :id => 1
Chris@0 51 assert_response :success
Chris@0 52 assert_template 'show'
Chris@0 53 assert_not_nil assigns(:board)
Chris@0 54 assert_not_nil assigns(:project)
Chris@0 55 assert_not_nil assigns(:topics)
Chris@0 56 end
Chris@909 57
Chris@1115 58 def test_show_should_display_sticky_messages_first
Chris@1115 59 Message.update_all(:sticky => 0)
Chris@1115 60 Message.update_all({:sticky => 1}, {:id => 1})
Chris@1115 61
Chris@1115 62 get :show, :project_id => 1, :id => 1
Chris@1115 63 assert_response :success
Chris@1115 64
Chris@1115 65 topics = assigns(:topics)
Chris@1115 66 assert_not_nil topics
Chris@1115 67 assert topics.size > 1, "topics size was #{topics.size}"
Chris@1115 68 assert topics.first.sticky?
Chris@1115 69 assert topics.first.updated_on < topics.second.updated_on
Chris@1115 70 end
Chris@1115 71
Chris@1115 72 def test_show_with_permission_should_display_the_new_message_form
Chris@1115 73 @request.session[:user_id] = 2
Chris@1115 74 get :show, :project_id => 1, :id => 1
Chris@1115 75 assert_response :success
Chris@1115 76 assert_template 'show'
Chris@1115 77
Chris@1115 78 assert_tag 'form', :attributes => {:id => 'message-form'}
Chris@1115 79 assert_tag 'input', :attributes => {:name => 'message[subject]'}
Chris@1115 80 end
Chris@1115 81
Chris@0 82 def test_show_atom
Chris@0 83 get :show, :project_id => 1, :id => 1, :format => 'atom'
Chris@0 84 assert_response :success
Chris@1115 85 assert_template 'common/feed'
Chris@0 86 assert_not_nil assigns(:board)
Chris@0 87 assert_not_nil assigns(:project)
Chris@0 88 assert_not_nil assigns(:messages)
Chris@0 89 end
Chris@909 90
Chris@1115 91 def test_show_not_found
Chris@1115 92 get :index, :project_id => 1, :id => 97
Chris@1115 93 assert_response 404
Chris@1115 94 end
Chris@1115 95
Chris@1115 96 def test_new
Chris@1115 97 @request.session[:user_id] = 2
Chris@1115 98 get :new, :project_id => 1
Chris@1115 99 assert_response :success
Chris@1115 100 assert_template 'new'
Chris@1115 101
Chris@1115 102 assert_select 'select[name=?]', 'board[parent_id]' do
Chris@1115 103 assert_select 'option', (Project.find(1).boards.size + 1)
Chris@1115 104 assert_select 'option[value=]', :text => ''
Chris@1115 105 assert_select 'option[value=1]', :text => 'Help'
Chris@1115 106 end
Chris@1115 107 end
Chris@1115 108
Chris@1115 109 def test_new_without_project_boards
Chris@1115 110 Project.find(1).boards.delete_all
Chris@1115 111 @request.session[:user_id] = 2
Chris@1115 112
Chris@1115 113 get :new, :project_id => 1
Chris@1115 114 assert_response :success
Chris@1115 115 assert_template 'new'
Chris@1115 116
Chris@1115 117 assert_select 'select[name=?]', 'board[parent_id]', 0
Chris@1115 118 end
Chris@1115 119
Chris@1115 120 def test_create
Chris@1115 121 @request.session[:user_id] = 2
Chris@1115 122 assert_difference 'Board.count' do
Chris@1115 123 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
Chris@1115 124 end
Chris@1115 125 assert_redirected_to '/projects/ecookbook/settings/boards'
Chris@1115 126 board = Board.first(:order => 'id DESC')
Chris@1115 127 assert_equal 'Testing', board.name
Chris@1115 128 assert_equal 'Testing board creation', board.description
Chris@1115 129 end
Chris@1115 130
Chris@1115 131 def test_create_with_parent
Chris@1115 132 @request.session[:user_id] = 2
Chris@1115 133 assert_difference 'Board.count' do
Chris@1115 134 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing', :parent_id => 2}
Chris@1115 135 end
Chris@1115 136 assert_redirected_to '/projects/ecookbook/settings/boards'
Chris@1115 137 board = Board.first(:order => 'id DESC')
Chris@1115 138 assert_equal Board.find(2), board.parent
Chris@1115 139 end
Chris@1115 140
Chris@1115 141 def test_create_with_failure
Chris@0 142 @request.session[:user_id] = 2
Chris@0 143 assert_no_difference 'Board.count' do
Chris@1115 144 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
Chris@1115 145 end
Chris@1115 146 assert_response :success
Chris@1115 147 assert_template 'new'
Chris@1115 148 end
Chris@1115 149
Chris@1115 150 def test_edit
Chris@1115 151 @request.session[:user_id] = 2
Chris@1115 152 get :edit, :project_id => 1, :id => 2
Chris@1115 153 assert_response :success
Chris@1115 154 assert_template 'edit'
Chris@1115 155 end
Chris@1115 156
Chris@1115 157 def test_edit_with_parent
Chris@1115 158 board = Board.generate!(:project_id => 1, :parent_id => 2)
Chris@1115 159 @request.session[:user_id] = 2
Chris@1115 160 get :edit, :project_id => 1, :id => board.id
Chris@1115 161 assert_response :success
Chris@1115 162 assert_template 'edit'
Chris@1115 163
Chris@1115 164 assert_select 'select[name=?]', 'board[parent_id]' do
Chris@1115 165 assert_select 'option[value=2][selected=selected]'
Chris@1115 166 end
Chris@1115 167 end
Chris@1115 168
Chris@1115 169 def test_update
Chris@1115 170 @request.session[:user_id] = 2
Chris@1115 171 assert_no_difference 'Board.count' do
Chris@1115 172 put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
Chris@0 173 end
Chris@0 174 assert_redirected_to '/projects/ecookbook/settings/boards'
Chris@0 175 assert_equal 'Testing', Board.find(2).name
Chris@0 176 end
Chris@909 177
Chris@929 178 def test_update_position
Chris@929 179 @request.session[:user_id] = 2
Chris@1115 180 put :update, :project_id => 1, :id => 2, :board => { :move_to => 'highest'}
Chris@929 181 assert_redirected_to '/projects/ecookbook/settings/boards'
Chris@929 182 board = Board.find(2)
Chris@929 183 assert_equal 1, board.position
Chris@929 184 end
Chris@929 185
Chris@1115 186 def test_update_with_failure
Chris@1115 187 @request.session[:user_id] = 2
Chris@1115 188 put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
Chris@1115 189 assert_response :success
Chris@1115 190 assert_template 'edit'
Chris@1115 191 end
Chris@1115 192
Chris@1115 193 def test_destroy
Chris@0 194 @request.session[:user_id] = 2
Chris@0 195 assert_difference 'Board.count', -1 do
Chris@1115 196 delete :destroy, :project_id => 1, :id => 2
Chris@0 197 end
Chris@0 198 assert_redirected_to '/projects/ecookbook/settings/boards'
Chris@0 199 assert_nil Board.find_by_id(2)
Chris@0 200 end
Chris@0 201 end