comparison test/functional/account_controller_test.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.expand_path('../../test_helper', __FILE__) 18 require File.expand_path('../../test_helper', __FILE__)
19 require 'account_controller'
20
21 # Re-raise errors caught by the controller.
22 class AccountController; def rescue_action(e) raise e end; end
23 19
24 class AccountControllerTest < ActionController::TestCase 20 class AccountControllerTest < ActionController::TestCase
25 fixtures :users, :roles 21 fixtures :users, :roles
26 22
27 def setup 23 def setup
28 @controller = AccountController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
31 User.current = nil 24 User.current = nil
32 end 25 end
33 26
34 def test_get_login 27 def test_get_login
35 get :login 28 get :login
36 assert_response :success 29 assert_response :success
37 assert_template 'login' 30 assert_template 'login'
38 31
39 assert_select 'input[name=username]' 32 assert_select 'input[name=username]'
40 assert_select 'input[name=password]' 33 assert_select 'input[name=password]'
34 end
35
36 def test_get_login_while_logged_in_should_redirect_to_home
37 @request.session[:user_id] = 2
38
39 get :login
40 assert_redirected_to '/'
41 assert_equal 2, @request.session[:user_id]
41 end 42 end
42 43
43 def test_login_should_redirect_to_back_url_param 44 def test_login_should_redirect_to_back_url_param
44 # request.uri is "test.host" in test environment 45 # request.uri is "test.host" in test environment
45 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.host/issues/show/1' 46 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.host/issues/show/1'
77 78
78 post :login, :username => 'jsmith', :password => 'jsmith' 79 post :login, :username => 'jsmith', :password => 'jsmith'
79 assert_response 302 80 assert_response 302
80 end 81 end
81 82
83 def test_get_logout_should_not_logout
84 @request.session[:user_id] = 2
85 get :logout
86 assert_response :success
87 assert_template 'logout'
88
89 assert_equal 2, @request.session[:user_id]
90 end
91
82 def test_logout 92 def test_logout
83 @request.session[:user_id] = 2 93 @request.session[:user_id] = 2
84 get :logout 94 post :logout
85 assert_redirected_to '/' 95 assert_redirected_to '/'
86 assert_nil @request.session[:user_id] 96 assert_nil @request.session[:user_id]
87 end 97 end
88 98
89 def test_logout_should_reset_session 99 def test_logout_should_reset_session
90 @controller.expects(:reset_session).once 100 @controller.expects(:reset_session).once
91 101
92 @request.session[:user_id] = 2 102 @request.session[:user_id] = 2
93 get :logout 103 post :logout
94 assert_response 302 104 assert_response 302
95 end 105 end
96 106
97 def test_get_register_with_registration_on 107 def test_get_register_with_registration_on
98 with_settings :self_registration => '3' do 108 with_settings :self_registration => '3' do
99 get :register 109 get :register
100 assert_response :success 110 assert_response :success
101 assert_template 'register' 111 assert_template 'register'
102 assert_not_nil assigns(:user) 112 assert_not_nil assigns(:user)
103 113
104 assert_tag 'input', :attributes => {:name => 'user[password]'} 114 assert_select 'input[name=?]', 'user[password]'
105 assert_tag 'input', :attributes => {:name => 'user[password_confirmation]'} 115 assert_select 'input[name=?]', 'user[password_confirmation]'
116 end
117 end
118
119 def test_get_register_should_detect_user_language
120 with_settings :self_registration => '3' do
121 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
122 get :register
123 assert_response :success
124 assert_not_nil assigns(:user)
125 assert_equal 'fr', assigns(:user).language
126 assert_select 'select[name=?]', 'user[language]' do
127 assert_select 'option[value=fr][selected=selected]'
128 end
106 end 129 end
107 end 130 end
108 131
109 def test_get_register_with_registration_off_should_redirect 132 def test_get_register_with_registration_off_should_redirect
110 with_settings :self_registration => '0' do 133 with_settings :self_registration => '0' do