Sha256: 302f46b831b34b2d5ac9b5500f19cfbc5792239b03229866273ad28f8e88c0b3

Contents?: true

Size: 1.71 KB

Versions: 19

Compression:

Stored size: 1.71 KB

Contents

require 'test/test_helper'

class RememberMeTest < ActionController::IntegrationTest

  def create_user_and_remember(add_to_token='')
    Devise.remember_for = 1
    user = create_user
    user.remember_me!
    cookies['warden.user.user.key'] = User.serialize_into_cookie(user) + add_to_token
    user
  end

  test 'do not remember the user if he has not checked remember me option' do
    user = sign_in_as_user
    assert_nil user.reload.remember_token
  end

  test 'generate remember token after sign in' do
    user = sign_in_as_user :remember_me => true
    assert_not_nil user.reload.remember_token
  end

  test 'remember the user before sign in' do
    user = create_user_and_remember
    get users_path
    assert_response :success
    assert warden.authenticated?(:user)
    assert warden.user(:user) == user
  end

  test 'do not remember with invalid token' do
    user = create_user_and_remember('add')
    get users_path
    assert_response :success
    assert_not warden.authenticated?(:user)
  end

  test 'do not remember with token expired' do
    user = create_user_and_remember
    Devise.remember_for = 0
    get users_path
    assert_response :success
    assert_not warden.authenticated?(:user)
  end

  test 'forget the user before sign out' do
    user = create_user_and_remember
    get users_path
    assert warden.authenticated?(:user)
    get destroy_user_session_path
    assert_not warden.authenticated?(:user)
    assert_nil user.reload.remember_token
  end

  test 'do not remember the user anymore after forget' do
    user = create_user_and_remember
    get users_path
    assert warden.authenticated?(:user)
    get destroy_user_session_path
    get users_path
    assert_not warden.authenticated?(:user)
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
devise-0.8.2 test/integration/rememberable_test.rb
devise-0.8.1 test/integration/rememberable_test.rb
devise-0.8.0 test/integration/rememberable_test.rb
devise-0.7.5 test/integration/rememberable_test.rb
devise-0.7.4 test/integration/rememberable_test.rb
devise-0.7.3 test/integration/rememberable_test.rb
devise-0.7.2 test/integration/rememberable_test.rb
devise-0.7.1 test/integration/rememberable_test.rb
devise-0.7.0 test/integration/rememberable_test.rb
devise-0.6.3 test/integration/rememberable_test.rb
devise-0.6.2 test/integration/rememberable_test.rb
devise-0.6.1 test/integration/rememberable_test.rb
devise-0.6.0 test/integration/rememberable_test.rb
devise-0.5.6 test/integration/rememberable_test.rb
devise-0.5.5 test/integration/rememberable_test.rb
devise-0.5.4 test/integration/rememberable_test.rb
devise-0.5.3 test/integration/rememberable_test.rb
devise-0.5.2 test/integration/rememberable_test.rb
devise-0.5.1 test/integration/rememberable_test.rb