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
|
2013-12-02 21:47:02 +00:00
|
|
|
post :create, :user => {:email => @user.email, :password => 'correct'}, :format => :json
|
2011-05-09 03:15:19 +00:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should return error if password is incorrect' do
|
2013-12-02 21:47:02 +00:00
|
|
|
post :create, :user => {:email => @user.email, :password => 'incorrect'}, :format => :json
|
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
|
2013-12-02 21:47:02 +00:00
|
|
|
get :destroy, :format => :json
|
2013-12-02 12:07:18 +00:00
|
|
|
assert_equal {}, session
|
2011-05-09 03:15:19 +00:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
end
|