Sha256: 12db52c1abd3c77e293c9c5cace49450246e271bc41d8635a518011db1adf9d0

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

require 'test_helper'

module ActsAsAuthenticTest
  class PersistenceTokenTest < ActiveSupport::TestCase
    def test_after_password_set_reset_persistence_token
      ben = users(:ben)
      old_persistence_token = ben.persistence_token
      ben.password = "newpass"
      assert_not_equal old_persistence_token, ben.persistence_token
    end

    def test_after_password_verification_reset_persistence_token
      aaron = users(:aaron)
      old_persistence_token = aaron.persistence_token

      assert aaron.valid_password?(password_for(aaron))
      assert_equal old_persistence_token, aaron.reload.persistence_token

      # only update it if it is nil
      assert aaron.update_attribute(:persistence_token, nil)
      assert aaron.valid_password?(password_for(aaron))
      assert_not_equal old_persistence_token, aaron.persistence_token
    end

    def test_before_validate_reset_persistence_token
      u = User.new
      refute u.valid?
      assert_not_nil u.persistence_token
    end

    def test_forget_all
      UserSession.allow_http_basic_auth = true

      http_basic_auth_for(users(:ben)) { UserSession.find }
      http_basic_auth_for(users(:zack)) { UserSession.find(:ziggity_zack) }
      assert UserSession.find
      assert UserSession.find(:ziggity_zack)
      User.forget_all
      refute UserSession.find
      refute UserSession.find(:ziggity_zack)
    end

    def test_forget
      UserSession.allow_http_basic_auth = true

      ben = users(:ben)
      zack = users(:zack)
      http_basic_auth_for(ben) { UserSession.find }
      http_basic_auth_for(zack) { UserSession.find(:ziggity_zack) }

      assert ben.reload.logged_in?
      assert zack.reload.logged_in?

      ben.forget!

      refute UserSession.find
      assert UserSession.find(:ziggity_zack)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
authlogic-4.0.1 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-4.0.0 test/acts_as_authentic_test/persistence_token_test.rb