2011-05-09 03:15:19 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class SessionsControllerTest < ActionController::TestCase
|
|
|
|
include Devise::TestHelpers
|
|
|
|
setup do
|
|
|
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
2011-05-15 23:55:37 +00:00
|
|
|
@user = users(:erik)
|
2011-05-09 03:15:19 +00:00
|
|
|
end
|
|
|
|
|
2011-12-25 07:23:19 +00:00
|
|
|
test 'should redirect to root path' do
|
2011-05-09 03:15:19 +00:00
|
|
|
get :new
|
2011-12-25 07:23:19 +00:00
|
|
|
assert_response :redirect
|
2011-05-09 03:15:19 +00:00
|
|
|
end
|
|
|
|
|
2011-05-15 23:33:32 +00:00
|
|
|
test 'should redirect if user is already authenticated' do
|
|
|
|
sign_in @user
|
|
|
|
get :new
|
|
|
|
assert_response :redirect
|
|
|
|
end
|
|
|
|
|
2011-05-09 03:15:19 +00:00
|
|
|
test 'should authenticate user if password is correct' do
|
2012-06-18 17:49:28 +00:00
|
|
|
post :create, user: {email: @user.email, password: 'correct'}
|
2011-05-09 03:15:19 +00:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should return error if password is incorrect' do
|
2012-06-18 17:49:28 +00:00
|
|
|
post :create, user: {email: @user.email, password: 'incorrect'}
|
2011-05-09 03:15:19 +00:00
|
|
|
assert_response 401
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should empty session on sign out' do
|
2011-05-15 23:33:32 +00:00
|
|
|
sign_in @user
|
2011-05-09 03:15:19 +00:00
|
|
|
get :destroy
|
|
|
|
assert_equal Hash.new, session
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
end
|