Sha256: 58af99babe729ab18c3ca38bc1d31f58578588b08a43422d5c073bc139ba1441

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

require 'abstract_unit'
require 'action_dispatch/middleware/session/abstract_store'

module ActionDispatch
  module Session
    class AbstractStoreTest < ActiveSupport::TestCase
      class MemoryStore < AbstractStore
        def initialize(app)
          @sessions = {}
          super
        end

        def get_session(env, sid)
          sid ||= 1
          session = @sessions[sid] ||= {}
          [sid, session]
        end

        def set_session(env, sid, session, options)
          @sessions[sid] = session
        end
      end

      def test_session_is_set
        env = {}
        as = MemoryStore.new app
        as.call(env)

        assert @env
        assert Request::Session.find @env
      end

      def test_new_session_object_is_merged_with_old
        env = {}
        as = MemoryStore.new app
        as.call(env)

        assert @env
        session = Request::Session.find @env
        session['foo'] = 'bar'

        as.call(@env)
        session1 = Request::Session.find @env

        assert_not_equal session, session1
        assert_equal session.to_hash, session1.to_hash
      end

      private
      def app(&block)
        @env = nil
        lambda { |env| @env = env }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activejob-lock-0.0.2 rails/actionpack/test/dispatch/session/abstract_store_test.rb
activejob-lock-0.0.1 rails/actionpack/test/dispatch/session/abstract_store_test.rb