Sha256: 03daf8f911e57a9febe41e8e6de0310044d55fc7388b098457cd83df6ef1eea8

Contents?: true

Size: 1.86 KB

Versions: 33

Compression:

Stored size: 1.86 KB

Contents

require 'test/test_helper'

class TokenAuthenticatableTest < ActiveSupport::TestCase

  test 'should generate friendly authentication token on create' do
    User.expects(:authentication_token).returns(VALID_AUTHENTICATION_TOKEN)
    user = create_user
    assert_present user.authentication_token
    assert_equal VALID_AUTHENTICATION_TOKEN, user.authentication_token
  end

  test 'should reset authentication token' do
    user = new_user
    user.reset_authentication_token
    previous_token = user.authentication_token
    user.reset_authentication_token
    assert_not_equal previous_token, user.authentication_token
  end

  test 'should ensure authentication token' do
    user = new_user
    user.ensure_authentication_token
    previous_token = user.authentication_token
    user.ensure_authentication_token
    assert_equal previous_token, user.authentication_token
  end

  test 'should test for a valid authentication token' do
    User.expects(:authentication_token).returns(VALID_AUTHENTICATION_TOKEN)
    user = create_user
    assert user.valid_authentication_token?(VALID_AUTHENTICATION_TOKEN)
    assert_not user.valid_authentication_token?(VALID_AUTHENTICATION_TOKEN.reverse)
  end

  test 'should authenticate a valid user with authentication token and return it' do
    User.expects(:authentication_token).returns(VALID_AUTHENTICATION_TOKEN)
    user = create_user
    user.confirm!
    authenticated_user = User.authenticate_with_token(:auth_token => user.authentication_token)
    assert_equal authenticated_user, user
  end

  test 'should return nil when authenticating an invalid user by authentication token' do
    User.expects(:authentication_token).returns(VALID_AUTHENTICATION_TOKEN)
    user = create_user
    user.confirm!
    authenticated_user = User.authenticate_with_token(:auth_token => user.authentication_token.reverse)
    assert_nil authenticated_user
  end

end

Version data entries

33 entries across 28 versions & 7 rubygems

Version Path
graffititracker_devise-1.0.11 test/models/token_authenticatable_test.rb
devise-1.0.11 test/models/token_authenticatable_test.rb
devise-1.0.10 test/models/token_authenticatable_test.rb
devise_ennder-1.4.1.0.9 test/models/token_authenticatable_test.rb
devise_ennder-1.4.1.0.9 test/rails_app/vendor/plugins/devise/test/models/token_authenticatable_test.rb
devise_ennder-1.3.1.0.9 test/models/token_authenticatable_test.rb
devise_ennder-1.3.1.0.9 test/rails_app/vendor/plugins/devise/test/models/token_authenticatable_test.rb
devise_ennder-1.2.1.0.9 test/models/token_authenticatable_test.rb
devise_ennder-1.2.1.0.9 test/rails_app/vendor/plugins/devise/test/models/token_authenticatable_test.rb
devise_ennder-1.1.1.0.9 test/models/token_authenticatable_test.rb
devise_ennder-1.1.1.0.9 test/rails_app/vendor/plugins/devise/test/models/token_authenticatable_test.rb
devise_ennder-1.0.1.0.9 test/models/token_authenticatable_test.rb
devise_ennder-1.0.1.0.9 test/rails_app/vendor/plugins/devise/test/models/token_authenticatable_test.rb
devise-1.0.9 test/models/token_authenticatable_test.rb
dcu-devise-1.0.7 test/models/token_authenticatable_test.rb
devise-1.0.8 test/models/token_authenticatable_test.rb
ivanvc-devise-1.0.7.1 test/models/token_authenticatable_test.rb
mongoid-devise-1.0.1 test/models/token_authenticatable_test.rb
devise-1.0.7 test/models/token_authenticatable_test.rb
devise-1.0.6 test/models/token_authenticatable_test.rb