Add tests for sessions controller
This commit is contained in:
parent
e71c3ee8ad
commit
b4c6028a88
|
@ -9,7 +9,7 @@ class SessionsController < Devise::SessionsController
|
|||
sign_in(resource_name, resource)
|
||||
render(:json => resource)
|
||||
else
|
||||
render(:json => {"errors" => {:password => ["You need to sign in or sign up before continuing."]}})
|
||||
render(:json => {"errors" => {:password => ["You need to sign in or sign up before continuing."]}}, :status => 401)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
user:
|
||||
name: User
|
||||
organization: Code for America
|
||||
email: user@example.com
|
||||
voice_number: 1234567890
|
||||
sms_number: 1234567890
|
||||
encrypted_password: "$2a$10$KF/JMZ494ZLhWLgHZeBTf.cSL4l0Wjij4gIZP7BzkueAC1p4nW0ma"
|
|
@ -0,0 +1,36 @@
|
|||
require 'test_helper'
|
||||
|
||||
class SessionsControllerTest < ActionController::TestCase
|
||||
include Devise::TestHelpers
|
||||
setup do
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
end
|
||||
|
||||
test 'should render combo form' do
|
||||
get :new
|
||||
assert_response :success
|
||||
assert_select 'form' do
|
||||
assert_select '[action=?]', '/users/sign_in'
|
||||
assert_select '[method=?]', 'post'
|
||||
end
|
||||
assert_select 'h2', 'Adopt this Hydrant'
|
||||
assert_select 'input', :count => 15
|
||||
assert_select 'label', :count => 10
|
||||
end
|
||||
|
||||
test 'should authenticate user if password is correct' do
|
||||
post :create, :user => {:email => 'user@example.com', :password => 'correct'}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test 'should return error if password is incorrect' do
|
||||
post :create, :user => {:email => 'user@example.com', :password => 'incorrect'}
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
test 'should empty session on sign out' do
|
||||
get :destroy
|
||||
assert_equal Hash.new, session
|
||||
assert_response :success
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue