annotate test/functional/boards_controller_test.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents dffacf8a6908
children
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 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@1517 60 Message.where({:id => 1}).update_all({:sticky => 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@1294 72 def test_show_should_display_message_with_last_reply_first
Chris@1294 73 Message.update_all(:sticky => 0)
Chris@1294 74
Chris@1294 75 # Reply to an old topic
Chris@1294 76 old_topic = Message.where(:board_id => 1, :parent_id => nil).order('created_on ASC').first
Chris@1294 77 reply = Message.new(:board_id => 1, :subject => 'New reply', :content => 'New reply', :author_id => 2)
Chris@1294 78 old_topic.children << reply
Chris@1294 79
Chris@1294 80 get :show, :project_id => 1, :id => 1
Chris@1294 81 assert_response :success
Chris@1294 82 topics = assigns(:topics)
Chris@1294 83 assert_not_nil topics
Chris@1294 84 assert_equal old_topic, topics.first
Chris@1294 85 end
Chris@1294 86
Chris@1115 87 def test_show_with_permission_should_display_the_new_message_form
Chris@1115 88 @request.session[:user_id] = 2
Chris@1115 89 get :show, :project_id => 1, :id => 1
Chris@1115 90 assert_response :success
Chris@1115 91 assert_template 'show'
Chris@1115 92
Chris@1464 93 assert_select 'form#message-form' do
Chris@1464 94 assert_select 'input[name=?]', 'message[subject]'
Chris@1464 95 end
Chris@1115 96 end
Chris@1115 97
Chris@0 98 def test_show_atom
Chris@0 99 get :show, :project_id => 1, :id => 1, :format => 'atom'
Chris@0 100 assert_response :success
Chris@1115 101 assert_template 'common/feed'
Chris@0 102 assert_not_nil assigns(:board)
Chris@0 103 assert_not_nil assigns(:project)
Chris@0 104 assert_not_nil assigns(:messages)
Chris@0 105 end
Chris@909 106
Chris@1115 107 def test_show_not_found
Chris@1115 108 get :index, :project_id => 1, :id => 97
Chris@1115 109 assert_response 404
Chris@1115 110 end
Chris@1115 111
Chris@1115 112 def test_new
Chris@1115 113 @request.session[:user_id] = 2
Chris@1115 114 get :new, :project_id => 1
Chris@1115 115 assert_response :success
Chris@1115 116 assert_template 'new'
Chris@1115 117
Chris@1115 118 assert_select 'select[name=?]', 'board[parent_id]' do
Chris@1115 119 assert_select 'option', (Project.find(1).boards.size + 1)
Chris@1464 120 assert_select 'option[value=]', :text => '&nbsp;'
Chris@1115 121 assert_select 'option[value=1]', :text => 'Help'
Chris@1115 122 end
Chris@1115 123 end
Chris@1115 124
Chris@1115 125 def test_new_without_project_boards
Chris@1115 126 Project.find(1).boards.delete_all
Chris@1115 127 @request.session[:user_id] = 2
Chris@1115 128
Chris@1115 129 get :new, :project_id => 1
Chris@1115 130 assert_response :success
Chris@1115 131 assert_template 'new'
Chris@1115 132
Chris@1115 133 assert_select 'select[name=?]', 'board[parent_id]', 0
Chris@1115 134 end
Chris@1115 135
Chris@1115 136 def test_create
Chris@1115 137 @request.session[:user_id] = 2
Chris@1115 138 assert_difference 'Board.count' do
Chris@1115 139 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
Chris@1115 140 end
Chris@1115 141 assert_redirected_to '/projects/ecookbook/settings/boards'
Chris@1517 142 board = Board.order('id DESC').first
Chris@1115 143 assert_equal 'Testing', board.name
Chris@1115 144 assert_equal 'Testing board creation', board.description
Chris@1115 145 end
Chris@1115 146
Chris@1115 147 def test_create_with_parent
Chris@1115 148 @request.session[:user_id] = 2
Chris@1115 149 assert_difference 'Board.count' do
Chris@1115 150 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing', :parent_id => 2}
Chris@1115 151 end
Chris@1115 152 assert_redirected_to '/projects/ecookbook/settings/boards'
Chris@1517 153 board = Board.order('id DESC').first
Chris@1115 154 assert_equal Board.find(2), board.parent
Chris@1115 155 end
Chris@1115 156
Chris@1115 157 def test_create_with_failure
Chris@0 158 @request.session[:user_id] = 2
Chris@0 159 assert_no_difference 'Board.count' do
Chris@1115 160 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
Chris@1115 161 end
Chris@1115 162 assert_response :success
Chris@1115 163 assert_template 'new'
Chris@1115 164 end
Chris@1115 165
Chris@1115 166 def test_edit
Chris@1115 167 @request.session[:user_id] = 2
Chris@1115 168 get :edit, :project_id => 1, :id => 2
Chris@1115 169 assert_response :success
Chris@1115 170 assert_template 'edit'
Chris@1115 171 end
Chris@1115 172
Chris@1115 173 def test_edit_with_parent
Chris@1115 174 board = Board.generate!(:project_id => 1, :parent_id => 2)
Chris@1115 175 @request.session[:user_id] = 2
Chris@1115 176 get :edit, :project_id => 1, :id => board.id
Chris@1115 177 assert_response :success
Chris@1115 178 assert_template 'edit'
Chris@1115 179
Chris@1115 180 assert_select 'select[name=?]', 'board[parent_id]' do
Chris@1115 181 assert_select 'option[value=2][selected=selected]'
Chris@1115 182 end
Chris@1115 183 end
Chris@1115 184
Chris@1115 185 def test_update
Chris@1115 186 @request.session[:user_id] = 2
Chris@1115 187 assert_no_difference 'Board.count' do
Chris@1115 188 put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
Chris@0 189 end
Chris@0 190 assert_redirected_to '/projects/ecookbook/settings/boards'
Chris@0 191 assert_equal 'Testing', Board.find(2).name
Chris@0 192 end
Chris@909 193
Chris@929 194 def test_update_position
Chris@929 195 @request.session[:user_id] = 2
Chris@1115 196 put :update, :project_id => 1, :id => 2, :board => { :move_to => 'highest'}
Chris@929 197 assert_redirected_to '/projects/ecookbook/settings/boards'
Chris@929 198 board = Board.find(2)
Chris@929 199 assert_equal 1, board.position
Chris@929 200 end
Chris@929 201
Chris@1115 202 def test_update_with_failure
Chris@1115 203 @request.session[:user_id] = 2
Chris@1115 204 put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
Chris@1115 205 assert_response :success
Chris@1115 206 assert_template 'edit'
Chris@1115 207 end
Chris@1115 208
Chris@1115 209 def test_destroy
Chris@0 210 @request.session[:user_id] = 2
Chris@0 211 assert_difference 'Board.count', -1 do
Chris@1115 212 delete :destroy, :project_id => 1, :id => 2
Chris@0 213 end
Chris@0 214 assert_redirected_to '/projects/ecookbook/settings/boards'
Chris@0 215 assert_nil Board.find_by_id(2)
Chris@0 216 end
Chris@0 217 end