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