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

47 lines
1.2 KiB
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
test 'should render combo form' do
get :new
assert_response :success
2011-05-16 06:34:14 +00:00
assert_template :new
assert_select 'form#combo_form' do
2011-05-09 03:15:19 +00:00
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
2011-05-16 06:34:14 +00:00
assert_select 'input[name="commit"]', :count => 3
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
2011-05-15 23:33:32 +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
2011-05-15 23:33:32 +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