Sha256: 24d13c1d24031401effc1a3656e7b773a70c331d9a6ac4d65b811b86c0575520

Contents?: true

Size: 1.67 KB

Versions: 24

Compression:

Stored size: 1.67 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
      ben = users(:ben)
      old_persistence_token = ben.persistence_token
      assert ben.valid_password?(password_for(ben))
      assert_equal old_persistence_token, ben.persistence_token
      
      # only update it if it is nil
      assert ben.update_attribute(:persistence_token, nil)
      assert ben.valid_password?(password_for(ben))
      assert_not_equal old_persistence_token, ben.persistence_token
    end
    
    def test_before_validate_reset_persistence_token
      u = User.new
      assert !u.valid?
      assert_not_nil u.persistence_token
    end
    
    def test_forget_all
      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
      assert !UserSession.find
      assert !UserSession.find(:ziggity_zack)
    end
    
    def test_forget
      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!

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

Version data entries

24 entries across 24 versions & 9 rubygems

Version Path
authlogic-3.4.3 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.4.2 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.4.1 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.4.0 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.3.0 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.2.0 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.1.3 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.1.2 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.1.1 test/acts_as_authentic_test/persistence_token_test.rb
nulogy-authlogic-3.1.0.1 test/acts_as_authentic_test/persistence_token_test.rb
Empact-authlogic-3.1.0 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.1.0 test/acts_as_authentic_test/persistence_token_test.rb
Empact-authlogic-3.0.3 test/acts_as_authentic_test/persistence_token_test.rb
antlypls-authlogic-3.0.3 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.0.3 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.0.2 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.0.1 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-3.0.0 test/acts_as_authentic_test/persistence_token_test.rb
authlogic-rails3-2.2 test/acts_as_authentic_test/persistence_token_test.rb
kb-authlogic-2.1.7 test/acts_as_authentic_test/persistence_token_test.rb