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