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