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