annotate .svn/pristine/e8/e8617c549b31d54d1ecceb4d7305f89a7f9997a3.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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