adopt-a-hydrant/test/functional/sessions_controller_test.rb

38 lines
944 B
Ruby
Raw Normal View History

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
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
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
get :destroy, format: :json
assert_equal {}, session
2011-05-09 03:15:19 +00:00
assert_response :success
end
end