annotate .svn/pristine/d4/d44f6e60d7b8016faa2e5a38f23ad998d6d9c458.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 dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1517 19
Chris@1517 20 class MyControllerTest < ActionController::TestCase
Chris@1517 21 fixtures :users, :user_preferences, :roles, :projects, :members, :member_roles,
Chris@1517 22 :issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources
Chris@1517 23
Chris@1517 24 def setup
Chris@1517 25 @request.session[:user_id] = 2
Chris@1517 26 end
Chris@1517 27
Chris@1517 28 def test_index
Chris@1517 29 get :index
Chris@1517 30 assert_response :success
Chris@1517 31 assert_template 'page'
Chris@1517 32 end
Chris@1517 33
Chris@1517 34 def test_page
Chris@1517 35 get :page
Chris@1517 36 assert_response :success
Chris@1517 37 assert_template 'page'
Chris@1517 38 end
Chris@1517 39
Chris@1517 40 def test_page_with_timelog_block
Chris@1517 41 preferences = User.find(2).pref
Chris@1517 42 preferences[:my_page_layout] = {'top' => ['timelog']}
Chris@1517 43 preferences.save!
Chris@1517 44 TimeEntry.create!(:user => User.find(2), :spent_on => Date.yesterday, :issue_id => 1, :hours => 2.5, :activity_id => 10)
Chris@1517 45
Chris@1517 46 get :page
Chris@1517 47 assert_response :success
Chris@1517 48 assert_select 'tr.time-entry' do
Chris@1517 49 assert_select 'td.subject a[href=/issues/1]'
Chris@1517 50 assert_select 'td.hours', :text => '2.50'
Chris@1517 51 end
Chris@1517 52 end
Chris@1517 53
Chris@1517 54 def test_page_with_all_blocks
Chris@1517 55 blocks = MyController::BLOCKS.keys
Chris@1517 56 preferences = User.find(2).pref
Chris@1517 57 preferences[:my_page_layout] = {'top' => blocks}
Chris@1517 58 preferences.save!
Chris@1517 59
Chris@1517 60 get :page
Chris@1517 61 assert_response :success
Chris@1517 62 assert_select 'div.mypage-box', blocks.size
Chris@1517 63 end
Chris@1517 64
Chris@1517 65 def test_my_account_should_show_editable_custom_fields
Chris@1517 66 get :account
Chris@1517 67 assert_response :success
Chris@1517 68 assert_template 'account'
Chris@1517 69 assert_equal User.find(2), assigns(:user)
Chris@1517 70
Chris@1517 71 assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
Chris@1517 72 end
Chris@1517 73
Chris@1517 74 def test_my_account_should_not_show_non_editable_custom_fields
Chris@1517 75 UserCustomField.find(4).update_attribute :editable, false
Chris@1517 76
Chris@1517 77 get :account
Chris@1517 78 assert_response :success
Chris@1517 79 assert_template 'account'
Chris@1517 80 assert_equal User.find(2), assigns(:user)
Chris@1517 81
Chris@1517 82 assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
Chris@1517 83 end
Chris@1517 84
Chris@1517 85 def test_my_account_should_show_language_select
Chris@1517 86 get :account
Chris@1517 87 assert_response :success
Chris@1517 88 assert_select 'select[name=?]', 'user[language]'
Chris@1517 89 end
Chris@1517 90
Chris@1517 91 def test_my_account_should_not_show_language_select_with_force_default_language_for_loggedin
Chris@1517 92 with_settings :force_default_language_for_loggedin => '1' do
Chris@1517 93 get :account
Chris@1517 94 assert_response :success
Chris@1517 95 assert_select 'select[name=?]', 'user[language]', 0
Chris@1517 96 end
Chris@1517 97 end
Chris@1517 98
Chris@1517 99 def test_update_account
Chris@1517 100 post :account,
Chris@1517 101 :user => {
Chris@1517 102 :firstname => "Joe",
Chris@1517 103 :login => "root",
Chris@1517 104 :admin => 1,
Chris@1517 105 :group_ids => ['10'],
Chris@1517 106 :custom_field_values => {"4" => "0100562500"}
Chris@1517 107 }
Chris@1517 108
Chris@1517 109 assert_redirected_to '/my/account'
Chris@1517 110 user = User.find(2)
Chris@1517 111 assert_equal user, assigns(:user)
Chris@1517 112 assert_equal "Joe", user.firstname
Chris@1517 113 assert_equal "jsmith", user.login
Chris@1517 114 assert_equal "0100562500", user.custom_value_for(4).value
Chris@1517 115 # ignored
Chris@1517 116 assert !user.admin?
Chris@1517 117 assert user.groups.empty?
Chris@1517 118 end
Chris@1517 119
Chris@1517 120 def test_my_account_should_show_destroy_link
Chris@1517 121 get :account
Chris@1517 122 assert_select 'a[href=/my/account/destroy]'
Chris@1517 123 end
Chris@1517 124
Chris@1517 125 def test_get_destroy_should_display_the_destroy_confirmation
Chris@1517 126 get :destroy
Chris@1517 127 assert_response :success
Chris@1517 128 assert_template 'destroy'
Chris@1517 129 assert_select 'form[action=/my/account/destroy]' do
Chris@1517 130 assert_select 'input[name=confirm]'
Chris@1517 131 end
Chris@1517 132 end
Chris@1517 133
Chris@1517 134 def test_post_destroy_without_confirmation_should_not_destroy_account
Chris@1517 135 assert_no_difference 'User.count' do
Chris@1517 136 post :destroy
Chris@1517 137 end
Chris@1517 138 assert_response :success
Chris@1517 139 assert_template 'destroy'
Chris@1517 140 end
Chris@1517 141
Chris@1517 142 def test_post_destroy_without_confirmation_should_destroy_account
Chris@1517 143 assert_difference 'User.count', -1 do
Chris@1517 144 post :destroy, :confirm => '1'
Chris@1517 145 end
Chris@1517 146 assert_redirected_to '/'
Chris@1517 147 assert_match /deleted/i, flash[:notice]
Chris@1517 148 end
Chris@1517 149
Chris@1517 150 def test_post_destroy_with_unsubscribe_not_allowed_should_not_destroy_account
Chris@1517 151 User.any_instance.stubs(:own_account_deletable?).returns(false)
Chris@1517 152
Chris@1517 153 assert_no_difference 'User.count' do
Chris@1517 154 post :destroy, :confirm => '1'
Chris@1517 155 end
Chris@1517 156 assert_redirected_to '/my/account'
Chris@1517 157 end
Chris@1517 158
Chris@1517 159 def test_change_password
Chris@1517 160 get :password
Chris@1517 161 assert_response :success
Chris@1517 162 assert_template 'password'
Chris@1517 163
Chris@1517 164 # non matching password confirmation
Chris@1517 165 post :password, :password => 'jsmith',
Chris@1517 166 :new_password => 'secret123',
Chris@1517 167 :new_password_confirmation => 'secret1234'
Chris@1517 168 assert_response :success
Chris@1517 169 assert_template 'password'
Chris@1517 170 assert_error_tag :content => /Password doesn&#x27;t match confirmation/
Chris@1517 171
Chris@1517 172 # wrong password
Chris@1517 173 post :password, :password => 'wrongpassword',
Chris@1517 174 :new_password => 'secret123',
Chris@1517 175 :new_password_confirmation => 'secret123'
Chris@1517 176 assert_response :success
Chris@1517 177 assert_template 'password'
Chris@1517 178 assert_equal 'Wrong password', flash[:error]
Chris@1517 179
Chris@1517 180 # good password
Chris@1517 181 post :password, :password => 'jsmith',
Chris@1517 182 :new_password => 'secret123',
Chris@1517 183 :new_password_confirmation => 'secret123'
Chris@1517 184 assert_redirected_to '/my/account'
Chris@1517 185 assert User.try_to_login('jsmith', 'secret123')
Chris@1517 186 end
Chris@1517 187
Chris@1517 188 def test_change_password_should_redirect_if_user_cannot_change_its_password
Chris@1517 189 User.find(2).update_attribute(:auth_source_id, 1)
Chris@1517 190
Chris@1517 191 get :password
Chris@1517 192 assert_not_nil flash[:error]
Chris@1517 193 assert_redirected_to '/my/account'
Chris@1517 194 end
Chris@1517 195
Chris@1517 196 def test_page_layout
Chris@1517 197 get :page_layout
Chris@1517 198 assert_response :success
Chris@1517 199 assert_template 'page_layout'
Chris@1517 200 end
Chris@1517 201
Chris@1517 202 def test_add_block
Chris@1517 203 post :add_block, :block => 'issuesreportedbyme'
Chris@1517 204 assert_redirected_to '/my/page_layout'
Chris@1517 205 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
Chris@1517 206 end
Chris@1517 207
Chris@1517 208 def test_add_invalid_block_should_redirect
Chris@1517 209 post :add_block, :block => 'invalid'
Chris@1517 210 assert_redirected_to '/my/page_layout'
Chris@1517 211 end
Chris@1517 212
Chris@1517 213 def test_remove_block
Chris@1517 214 post :remove_block, :block => 'issuesassignedtome'
Chris@1517 215 assert_redirected_to '/my/page_layout'
Chris@1517 216 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
Chris@1517 217 end
Chris@1517 218
Chris@1517 219 def test_order_blocks
Chris@1517 220 xhr :post, :order_blocks, :group => 'left', 'blocks' => ['documents', 'calendar', 'latestnews']
Chris@1517 221 assert_response :success
Chris@1517 222 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
Chris@1517 223 end
Chris@1517 224
Chris@1517 225 def test_reset_rss_key_with_existing_key
Chris@1517 226 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
Chris@1517 227 post :reset_rss_key
Chris@1517 228
Chris@1517 229 assert_not_equal @previous_token_value, User.find(2).rss_key
Chris@1517 230 assert User.find(2).rss_token
Chris@1517 231 assert_match /reset/, flash[:notice]
Chris@1517 232 assert_redirected_to '/my/account'
Chris@1517 233 end
Chris@1517 234
Chris@1517 235 def test_reset_rss_key_without_existing_key
Chris@1517 236 assert_nil User.find(2).rss_token
Chris@1517 237 post :reset_rss_key
Chris@1517 238
Chris@1517 239 assert User.find(2).rss_token
Chris@1517 240 assert_match /reset/, flash[:notice]
Chris@1517 241 assert_redirected_to '/my/account'
Chris@1517 242 end
Chris@1517 243
Chris@1517 244 def test_reset_api_key_with_existing_key
Chris@1517 245 @previous_token_value = User.find(2).api_key # Will generate one if it's missing
Chris@1517 246 post :reset_api_key
Chris@1517 247
Chris@1517 248 assert_not_equal @previous_token_value, User.find(2).api_key
Chris@1517 249 assert User.find(2).api_token
Chris@1517 250 assert_match /reset/, flash[:notice]
Chris@1517 251 assert_redirected_to '/my/account'
Chris@1517 252 end
Chris@1517 253
Chris@1517 254 def test_reset_api_key_without_existing_key
Chris@1517 255 assert_nil User.find(2).api_token
Chris@1517 256 post :reset_api_key
Chris@1517 257
Chris@1517 258 assert User.find(2).api_token
Chris@1517 259 assert_match /reset/, flash[:notice]
Chris@1517 260 assert_redirected_to '/my/account'
Chris@1517 261 end
Chris@1517 262 end