##// END OF EJS Templates
Test failure....
Jean-Philippe Lang -
r9761:c02594af96cd
parent child
Show More
@@ -1,185 +1,188
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'account_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class AccountController; def rescue_action(e) raise e end; end
23 23
24 24 class AccountControllerTest < ActionController::TestCase
25 25 fixtures :users, :roles
26 26
27 27 def setup
28 28 @controller = AccountController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_login_should_redirect_to_back_url_param
35 35 # request.uri is "test.host" in test environment
36 36 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.host%2Fissues%2Fshow%2F1'
37 37 assert_redirected_to '/issues/show/1'
38 38 end
39 39
40 40 def test_login_should_not_redirect_to_another_host
41 41 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.foo%2Ffake'
42 42 assert_redirected_to '/my/page'
43 43 end
44 44
45 45 def test_login_with_wrong_password
46 46 post :login, :username => 'admin', :password => 'bad'
47 47 assert_response :success
48 48 assert_template 'login'
49 49 assert_tag 'div',
50 50 :attributes => { :class => "flash error" },
51 51 :content => /Invalid user or password/
52 52 end
53 53
54 54 def test_login_should_rescue_auth_source_exception
55 55 source = AuthSource.create!(:name => 'Test')
56 56 User.find(2).update_attribute :auth_source_id, source.id
57 57 AuthSource.any_instance.stubs(:authenticate).raises(AuthSourceException.new("Something wrong"))
58 58
59 59 post :login, :username => 'jsmith', :password => 'jsmith'
60 60 assert_response 500
61 61 assert_error_tag :content => /Something wrong/
62 62 end
63 63
64 64 def test_login_should_reset_session
65 65 @controller.expects(:reset_session).once
66 66
67 67 post :login, :username => 'jsmith', :password => 'jsmith'
68 68 assert_response 302
69 69 end
70 70
71 71 def test_logout
72 72 @request.session[:user_id] = 2
73 73 get :logout
74 74 assert_redirected_to '/'
75 75 assert_nil @request.session[:user_id]
76 76 end
77 77
78 78 def test_logout_should_reset_session
79 79 @controller.expects(:reset_session).once
80 80
81 81 @request.session[:user_id] = 2
82 82 get :logout
83 83 assert_response 302
84 84 end
85 85
86 86 def test_get_register_with_registration_on
87 87 with_settings :self_registration => '3' do
88 88 get :register
89 89 assert_response :success
90 90 assert_template 'register'
91 91 assert_not_nil assigns(:user)
92 92
93 93 assert_tag 'input', :attributes => {:name => 'user[password]'}
94 94 assert_tag 'input', :attributes => {:name => 'user[password_confirmation]'}
95 95 end
96 96 end
97 97
98 98 def test_get_register_with_registration_off_should_redirect
99 99 with_settings :self_registration => '0' do
100 100 get :register
101 101 assert_redirected_to '/'
102 102 end
103 103 end
104 104
105 105 # See integration/account_test.rb for the full test
106 106 def test_post_register_with_registration_on
107 107 with_settings :self_registration => '3' do
108 108 assert_difference 'User.count' do
109 109 post :register, :user => {
110 110 :login => 'register',
111 111 :password => 'test',
112 112 :password_confirmation => 'test',
113 113 :firstname => 'John',
114 114 :lastname => 'Doe',
115 115 :mail => 'register@example.com'
116 116 }
117 117 assert_redirected_to '/my/account'
118 118 end
119 119 user = User.first(:order => 'id DESC')
120 120 assert_equal 'register', user.login
121 121 assert_equal 'John', user.firstname
122 122 assert_equal 'Doe', user.lastname
123 123 assert_equal 'register@example.com', user.mail
124 124 assert user.check_password?('test')
125 125 assert user.active?
126 126 end
127 127 end
128 128
129 129 def test_post_register_with_registration_off_should_redirect
130 130 with_settings :self_registration => '0' do
131 131 assert_no_difference 'User.count' do
132 132 post :register, :user => {
133 133 :login => 'register',
134 134 :password => 'test',
135 135 :password_confirmation => 'test',
136 136 :firstname => 'John',
137 137 :lastname => 'Doe',
138 138 :mail => 'register@example.com'
139 139 }
140 140 assert_redirected_to '/'
141 141 end
142 142 end
143 143 end
144 144
145 145 def test_get_lost_password_should_display_lost_password_form
146 146 get :lost_password
147 147 assert_response :success
148 148 assert_select 'input[name=mail]'
149 149 end
150 150
151 151 def test_lost_password_for_active_user_should_create_a_token
152 Token.delete_all
152 153 assert_difference 'ActionMailer::Base.deliveries.size' do
153 154 assert_difference 'Token.count' do
154 155 with_settings :host_name => 'mydomain.foo', :protocol => 'http' do
155 156 post :lost_password, :mail => 'JSmith@somenet.foo'
156 157 assert_redirected_to '/login'
157 158 end
158 159 end
159 160 end
160 161
161 162 token = Token.order('id DESC').first
162 163 assert_equal User.find(2), token.user
163 164 assert_equal 'recovery', token.action
164 165
165 166 assert_select_email do
166 167 assert_select "a[href=?]", "http://mydomain.foo/account/lost_password?token=#{token.value}"
167 168 end
168 169 end
169 170
170 171 def test_lost_password_for_unknown_user_should_fail
172 Token.delete_all
171 173 assert_no_difference 'Token.count' do
172 174 post :lost_password, :mail => 'invalid@somenet.foo'
173 175 assert_response :success
174 176 end
175 177 end
176 178
177 179 def test_lost_password_for_non_active_user_should_fail
180 Token.delete_all
178 181 assert User.find(2).lock!
179 182
180 183 assert_no_difference 'Token.count' do
181 184 post :lost_password, :mail => 'JSmith@somenet.foo'
182 185 assert_response :success
183 186 end
184 187 end
185 188 end
General Comments 0
You need to be logged in to leave comments. Login now