annotate .svn/pristine/39/39db13c4cad8ea5def9b39b1a667edc1cb253f4e.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1296 19
Chris@1296 20 begin
Chris@1296 21 require 'mocha'
Chris@1296 22 rescue
Chris@1296 23 # Won't run some tests
Chris@1296 24 end
Chris@1296 25
Chris@1296 26 class AccountTest < ActionController::IntegrationTest
Chris@1296 27 fixtures :users, :roles
Chris@1296 28
Chris@1296 29 # Replace this with your real tests.
Chris@1296 30 def test_login
Chris@1296 31 get "my/page"
Chris@1296 32 assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fmy%2Fpage"
Chris@1296 33 log_user('jsmith', 'jsmith')
Chris@1296 34
Chris@1296 35 get "my/account"
Chris@1296 36 assert_response :success
Chris@1296 37 assert_template "my/account"
Chris@1296 38 end
Chris@1296 39
Chris@1296 40 def test_autologin
Chris@1296 41 user = User.find(1)
Chris@1296 42 Setting.autologin = "7"
Chris@1296 43 Token.delete_all
Chris@1296 44
Chris@1296 45 # User logs in with 'autologin' checked
Chris@1296 46 post '/login', :username => user.login, :password => 'admin', :autologin => 1
Chris@1296 47 assert_redirected_to '/my/page'
Chris@1296 48 token = Token.find :first
Chris@1296 49 assert_not_nil token
Chris@1296 50 assert_equal user, token.user
Chris@1296 51 assert_equal 'autologin', token.action
Chris@1296 52 assert_equal user.id, session[:user_id]
Chris@1296 53 assert_equal token.value, cookies['autologin']
Chris@1296 54
Chris@1296 55 # Session is cleared
Chris@1296 56 reset!
Chris@1296 57 User.current = nil
Chris@1296 58 # Clears user's last login timestamp
Chris@1296 59 user.update_attribute :last_login_on, nil
Chris@1296 60 assert_nil user.reload.last_login_on
Chris@1296 61
Chris@1296 62 # User comes back with his autologin cookie
Chris@1296 63 cookies[:autologin] = token.value
Chris@1296 64 get '/my/page'
Chris@1296 65 assert_response :success
Chris@1296 66 assert_template 'my/page'
Chris@1296 67 assert_equal user.id, session[:user_id]
Chris@1296 68 assert_not_nil user.reload.last_login_on
Chris@1296 69 end
Chris@1296 70
Chris@1296 71 def test_lost_password
Chris@1296 72 Token.delete_all
Chris@1296 73
Chris@1296 74 get "account/lost_password"
Chris@1296 75 assert_response :success
Chris@1296 76 assert_template "account/lost_password"
Chris@1296 77 assert_select 'input[name=mail]'
Chris@1296 78
Chris@1296 79 post "account/lost_password", :mail => 'jSmith@somenet.foo'
Chris@1296 80 assert_redirected_to "/login"
Chris@1296 81
Chris@1296 82 token = Token.find(:first)
Chris@1296 83 assert_equal 'recovery', token.action
Chris@1296 84 assert_equal 'jsmith@somenet.foo', token.user.mail
Chris@1296 85 assert !token.expired?
Chris@1296 86
Chris@1296 87 get "account/lost_password", :token => token.value
Chris@1296 88 assert_response :success
Chris@1296 89 assert_template "account/password_recovery"
Chris@1296 90 assert_select 'input[type=hidden][name=token][value=?]', token.value
Chris@1296 91 assert_select 'input[name=new_password]'
Chris@1296 92 assert_select 'input[name=new_password_confirmation]'
Chris@1296 93
Chris@1296 94 post "account/lost_password", :token => token.value, :new_password => 'newpass123', :new_password_confirmation => 'newpass123'
Chris@1296 95 assert_redirected_to "/login"
Chris@1296 96 assert_equal 'Password was successfully updated.', flash[:notice]
Chris@1296 97
Chris@1296 98 log_user('jsmith', 'newpass123')
Chris@1296 99 assert_equal 0, Token.count
Chris@1296 100 end
Chris@1296 101
Chris@1296 102 def test_register_with_automatic_activation
Chris@1296 103 Setting.self_registration = '3'
Chris@1296 104
Chris@1296 105 get 'account/register'
Chris@1296 106 assert_response :success
Chris@1296 107 assert_template 'account/register'
Chris@1296 108
Chris@1296 109 post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
Chris@1296 110 :password => "newpass123", :password_confirmation => "newpass123"}
Chris@1296 111 assert_redirected_to '/my/account'
Chris@1296 112 follow_redirect!
Chris@1296 113 assert_response :success
Chris@1296 114 assert_template 'my/account'
Chris@1296 115
Chris@1296 116 user = User.find_by_login('newuser')
Chris@1296 117 assert_not_nil user
Chris@1296 118 assert user.active?
Chris@1296 119 assert_not_nil user.last_login_on
Chris@1296 120 end
Chris@1296 121
Chris@1296 122 def test_register_with_manual_activation
Chris@1296 123 Setting.self_registration = '2'
Chris@1296 124
Chris@1296 125 post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
Chris@1296 126 :password => "newpass123", :password_confirmation => "newpass123"}
Chris@1296 127 assert_redirected_to '/login'
Chris@1296 128 assert !User.find_by_login('newuser').active?
Chris@1296 129 end
Chris@1296 130
Chris@1296 131 def test_register_with_email_activation
Chris@1296 132 Setting.self_registration = '1'
Chris@1296 133 Token.delete_all
Chris@1296 134
Chris@1296 135 post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
Chris@1296 136 :password => "newpass123", :password_confirmation => "newpass123"}
Chris@1296 137 assert_redirected_to '/login'
Chris@1296 138 assert !User.find_by_login('newuser').active?
Chris@1296 139
Chris@1296 140 token = Token.find(:first)
Chris@1296 141 assert_equal 'register', token.action
Chris@1296 142 assert_equal 'newuser@foo.bar', token.user.mail
Chris@1296 143 assert !token.expired?
Chris@1296 144
Chris@1296 145 get 'account/activate', :token => token.value
Chris@1296 146 assert_redirected_to '/login'
Chris@1296 147 log_user('newuser', 'newpass123')
Chris@1296 148 end
Chris@1296 149
Chris@1296 150 def test_onthefly_registration
Chris@1296 151 # disable registration
Chris@1296 152 Setting.self_registration = '0'
Chris@1296 153 AuthSource.expects(:authenticate).returns({:login => 'foo', :firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com', :auth_source_id => 66})
Chris@1296 154
Chris@1296 155 post '/login', :username => 'foo', :password => 'bar'
Chris@1296 156 assert_redirected_to '/my/page'
Chris@1296 157
Chris@1296 158 user = User.find_by_login('foo')
Chris@1296 159 assert user.is_a?(User)
Chris@1296 160 assert_equal 66, user.auth_source_id
Chris@1296 161 assert user.hashed_password.blank?
Chris@1296 162 end
Chris@1296 163
Chris@1296 164 def test_onthefly_registration_with_invalid_attributes
Chris@1296 165 # disable registration
Chris@1296 166 Setting.self_registration = '0'
Chris@1296 167 AuthSource.expects(:authenticate).returns({:login => 'foo', :lastname => 'Smith', :auth_source_id => 66})
Chris@1296 168
Chris@1296 169 post '/login', :username => 'foo', :password => 'bar'
Chris@1296 170 assert_response :success
Chris@1296 171 assert_template 'account/register'
Chris@1296 172 assert_tag :input, :attributes => { :name => 'user[firstname]', :value => '' }
Chris@1296 173 assert_tag :input, :attributes => { :name => 'user[lastname]', :value => 'Smith' }
Chris@1296 174 assert_no_tag :input, :attributes => { :name => 'user[login]' }
Chris@1296 175 assert_no_tag :input, :attributes => { :name => 'user[password]' }
Chris@1296 176
Chris@1296 177 post 'account/register', :user => {:firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com'}
Chris@1296 178 assert_redirected_to '/my/account'
Chris@1296 179
Chris@1296 180 user = User.find_by_login('foo')
Chris@1296 181 assert user.is_a?(User)
Chris@1296 182 assert_equal 66, user.auth_source_id
Chris@1296 183 assert user.hashed_password.blank?
Chris@1296 184 end
Chris@1296 185 end