Mercurial > hg > soundsoftware-site
comparison test/functional/account_controller_test.rb @ 1464:261b3d9a4903 redmine-2.4
Update to Redmine 2.4 branch rev 12663
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2014 14:37:42 +0000 |
parents | 433d4f72a19b |
children | e248c7af89ec |
comparison
equal
deleted
inserted
replaced
1296:038ba2d95de8 | 1464:261b3d9a4903 |
---|---|
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' |
60 assert_select 'input[name=username][value=admin]' | 61 assert_select 'input[name=username][value=admin]' |
61 assert_select 'input[name=password]' | 62 assert_select 'input[name=password]' |
62 assert_select 'input[name=password][value]', 0 | 63 assert_select 'input[name=password][value]', 0 |
63 end | 64 end |
64 | 65 |
66 def test_login_with_locked_account_should_fail | |
67 User.find(2).update_attribute :status, User::STATUS_LOCKED | |
68 | |
69 post :login, :username => 'jsmith', :password => 'jsmith' | |
70 assert_redirected_to '/login' | |
71 assert_include 'locked', flash[:error] | |
72 assert_nil @request.session[:user_id] | |
73 end | |
74 | |
75 def test_login_as_registered_user_with_manual_activation_should_inform_user | |
76 User.find(2).update_attribute :status, User::STATUS_REGISTERED | |
77 | |
78 with_settings :self_registration => '2', :default_language => 'en' do | |
79 post :login, :username => 'jsmith', :password => 'jsmith' | |
80 assert_redirected_to '/login' | |
81 assert_include 'pending administrator approval', flash[:error] | |
82 end | |
83 end | |
84 | |
85 def test_login_as_registered_user_with_email_activation_should_propose_new_activation_email | |
86 User.find(2).update_attribute :status, User::STATUS_REGISTERED | |
87 | |
88 with_settings :self_registration => '1', :default_language => 'en' do | |
89 post :login, :username => 'jsmith', :password => 'jsmith' | |
90 assert_redirected_to '/login' | |
91 assert_equal 2, @request.session[:registered_user_id] | |
92 assert_include 'new activation email', flash[:error] | |
93 end | |
94 end | |
95 | |
65 def test_login_should_rescue_auth_source_exception | 96 def test_login_should_rescue_auth_source_exception |
66 source = AuthSource.create!(:name => 'Test') | 97 source = AuthSource.create!(:name => 'Test') |
67 User.find(2).update_attribute :auth_source_id, source.id | 98 User.find(2).update_attribute :auth_source_id, source.id |
68 AuthSource.any_instance.stubs(:authenticate).raises(AuthSourceException.new("Something wrong")) | 99 AuthSource.any_instance.stubs(:authenticate).raises(AuthSourceException.new("Something wrong")) |
69 | 100 |
77 | 108 |
78 post :login, :username => 'jsmith', :password => 'jsmith' | 109 post :login, :username => 'jsmith', :password => 'jsmith' |
79 assert_response 302 | 110 assert_response 302 |
80 end | 111 end |
81 | 112 |
113 def test_get_logout_should_not_logout | |
114 @request.session[:user_id] = 2 | |
115 get :logout | |
116 assert_response :success | |
117 assert_template 'logout' | |
118 | |
119 assert_equal 2, @request.session[:user_id] | |
120 end | |
121 | |
122 def test_get_logout_with_anonymous_should_redirect | |
123 get :logout | |
124 assert_redirected_to '/' | |
125 end | |
126 | |
82 def test_logout | 127 def test_logout |
83 @request.session[:user_id] = 2 | 128 @request.session[:user_id] = 2 |
84 get :logout | 129 post :logout |
85 assert_redirected_to '/' | 130 assert_redirected_to '/' |
86 assert_nil @request.session[:user_id] | 131 assert_nil @request.session[:user_id] |
87 end | 132 end |
88 | 133 |
89 def test_logout_should_reset_session | 134 def test_logout_should_reset_session |
90 @controller.expects(:reset_session).once | 135 @controller.expects(:reset_session).once |
91 | 136 |
92 @request.session[:user_id] = 2 | 137 @request.session[:user_id] = 2 |
93 get :logout | 138 post :logout |
94 assert_response 302 | 139 assert_response 302 |
95 end | 140 end |
96 | 141 |
97 def test_get_register_with_registration_on | 142 def test_get_register_with_registration_on |
98 with_settings :self_registration => '3' do | 143 with_settings :self_registration => '3' do |
99 get :register | 144 get :register |
100 assert_response :success | 145 assert_response :success |
101 assert_template 'register' | 146 assert_template 'register' |
102 assert_not_nil assigns(:user) | 147 assert_not_nil assigns(:user) |
103 | 148 |
104 assert_tag 'input', :attributes => {:name => 'user[password]'} | 149 assert_select 'input[name=?]', 'user[password]' |
105 assert_tag 'input', :attributes => {:name => 'user[password_confirmation]'} | 150 assert_select 'input[name=?]', 'user[password_confirmation]' |
151 end | |
152 end | |
153 | |
154 def test_get_register_should_detect_user_language | |
155 with_settings :self_registration => '3' do | |
156 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3' | |
157 get :register | |
158 assert_response :success | |
159 assert_not_nil assigns(:user) | |
160 assert_equal 'fr', assigns(:user).language | |
161 assert_select 'select[name=?]', 'user[language]' do | |
162 assert_select 'option[value=fr][selected=selected]' | |
163 end | |
106 end | 164 end |
107 end | 165 end |
108 | 166 |
109 def test_get_register_with_registration_off_should_redirect | 167 def test_get_register_with_registration_off_should_redirect |
110 with_settings :self_registration => '0' do | 168 with_settings :self_registration => '0' do |
192 Token.delete_all | 250 Token.delete_all |
193 assert User.find(2).lock! | 251 assert User.find(2).lock! |
194 | 252 |
195 assert_no_difference 'Token.count' do | 253 assert_no_difference 'Token.count' do |
196 post :lost_password, :mail => 'JSmith@somenet.foo' | 254 post :lost_password, :mail => 'JSmith@somenet.foo' |
255 assert_redirected_to '/account/lost_password' | |
256 end | |
257 end | |
258 | |
259 def test_lost_password_for_user_who_cannot_change_password_should_fail | |
260 User.any_instance.stubs(:change_password_allowed?).returns(false) | |
261 | |
262 assert_no_difference 'Token.count' do | |
263 post :lost_password, :mail => 'JSmith@somenet.foo' | |
197 assert_response :success | 264 assert_response :success |
198 end | 265 end |
199 end | 266 end |
200 | 267 |
201 def test_get_lost_password_with_token_should_display_the_password_recovery_form | 268 def test_get_lost_password_with_token_should_display_the_password_recovery_form |
249 | 316 |
250 def test_post_lost_password_with_invalid_token_should_redirect | 317 def test_post_lost_password_with_invalid_token_should_redirect |
251 post :lost_password, :token => "abcdef", :new_password => 'newpass', :new_password_confirmation => 'newpass' | 318 post :lost_password, :token => "abcdef", :new_password => 'newpass', :new_password_confirmation => 'newpass' |
252 assert_redirected_to '/' | 319 assert_redirected_to '/' |
253 end | 320 end |
321 | |
322 def test_activation_email_should_send_an_activation_email | |
323 User.find(2).update_attribute :status, User::STATUS_REGISTERED | |
324 @request.session[:registered_user_id] = 2 | |
325 | |
326 with_settings :self_registration => '1' do | |
327 assert_difference 'ActionMailer::Base.deliveries.size' do | |
328 get :activation_email | |
329 assert_redirected_to '/login' | |
330 end | |
331 end | |
332 end | |
333 | |
334 def test_activation_email_without_session_data_should_fail | |
335 User.find(2).update_attribute :status, User::STATUS_REGISTERED | |
336 | |
337 with_settings :self_registration => '1' do | |
338 assert_no_difference 'ActionMailer::Base.deliveries.size' do | |
339 get :activation_email | |
340 assert_redirected_to '/' | |
341 end | |
342 end | |
343 end | |
254 end | 344 end |