annotate .svn/pristine/af/afff6ebb421c46aa468f585b7d8909132a409f4d.svn-base @ 1494:e248c7af89ec redmine-2.4

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