Sha256: 9828d7b0a4bceb5bd48c0cbc5fc4dcf1d78d9b62a124fb6c62ed7fcda1892b38

Contents?: true

Size: 1.34 KB

Versions: 12

Compression:

Stored size: 1.34 KB

Contents

require 'test_helper'

class WackyUserSession < Authlogic::Session::Base
  attr_accessor :counter
  authenticate_with User

  def initialize
    @counter = 0
    super
  end

  def persist_by_false
    self.counter += 1
    return false
  end

  def persist_by_true
    self.counter += 1
    return true
  end
end

module SessionTest
  class CallbacksTest < ActiveSupport::TestCase
    def setup
     WackyUserSession.reset_callbacks(:persist)
    end
    
    def test_no_callbacks
      assert_equal [], WackyUserSession._persist_callbacks.map(&:filter)
      session = WackyUserSession.new
      session.send(:persist)
      assert_equal 0, session.counter
    end

    def test_true_callback_cancelling_later_callbacks
      WackyUserSession.persist :persist_by_true, :persist_by_false
      assert_equal [:persist_by_true, :persist_by_false], WackyUserSession._persist_callbacks.map(&:filter)
  
      session = WackyUserSession.new
      session.send(:persist)
      assert_equal 1, session.counter
    end
  
    def test_false_callback_continuing_to_later_callbacks
      WackyUserSession.persist :persist_by_false, :persist_by_true
      assert_equal [:persist_by_false, :persist_by_true], WackyUserSession._persist_callbacks.map(&:filter)
  
      session = WackyUserSession.new
      session.send(:persist)
      assert_equal 2, session.counter
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
authlogic-3.4.3 test/session_test/callbacks_test.rb
authlogic-3.4.2 test/session_test/callbacks_test.rb
authlogic-3.4.1 test/session_test/callbacks_test.rb
authlogic-3.4.0 test/session_test/callbacks_test.rb
authlogic-3.3.0 test/session_test/callbacks_test.rb
authlogic-3.2.0 test/session_test/callbacks_test.rb
authlogic-3.1.3 test/session_test/callbacks_test.rb
authlogic-3.1.2 test/session_test/callbacks_test.rb
authlogic-3.1.1 test/session_test/callbacks_test.rb
nulogy-authlogic-3.1.0.1 test/session_test/callbacks_test.rb
Empact-authlogic-3.1.0 test/session_test/callbacks_test.rb
authlogic-3.1.0 test/session_test/callbacks_test.rb