Sha256: f70ef03b4638fac8330de8ff827a50dc6d299b24fbf24bd8acf0487f3839ea5c

Contents?: true

Size: 1014 Bytes

Versions: 42

Compression:

Stored size: 1014 Bytes

Contents

require 'minitest/autorun'
require 'rack/session/abstract/id'

describe Rack::Session::Abstract::SessionHash do
  attr_reader :hash

  def setup
    super
    store = Class.new do
      def load_session(req)
        ["id", {foo: :bar, baz: :qux}]
      end
      def session_exists?(req)
        true
      end
    end
    @hash = Rack::Session::Abstract::SessionHash.new(store.new, nil)
  end

  it "returns keys" do
    assert_equal ["foo", "baz"], hash.keys
  end

  it "returns values" do
    assert_equal [:bar, :qux], hash.values
  end

  describe "#fetch" do
    it "returns value for a matching key" do
      assert_equal :bar, hash.fetch(:foo)
    end

    it "works with a default value" do
      assert_equal :default, hash.fetch(:unknown, :default)
    end

    it "works with a block" do
      assert_equal :default, hash.fetch(:unkown) { :default }
    end

    it "it raises when fetching unknown keys without defaults" do
      lambda { hash.fetch(:unknown) }.must_raise KeyError
    end
  end
end

Version data entries

42 entries across 40 versions & 10 rubygems

Version Path
rack-2.0.9.4 test/spec_session_abstract_session_hash.rb
rack-2.0.9.3 test/spec_session_abstract_session_hash.rb
rack-2.0.9.2 test/spec_session_abstract_session_hash.rb
rack-2.0.9.1 test/spec_session_abstract_session_hash.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-2.0.5/test/spec_session_abstract_session_hash.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rack-2.0.8/test/spec_session_abstract_session_hash.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/test/spec_session_abstract_session_hash.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/test/spec_session_abstract_session_hash.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/test/spec_session_abstract_session_hash.rb
rack-2.0.9 test/spec_session_abstract_session_hash.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rack-2.0.8/test/spec_session_abstract_session_hash.rb
rack-2.0.8 test/spec_session_abstract_session_hash.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_session_abstract_session_hash.rb
tdiary-5.1.0 vendor/bundle/gems/rack-2.0.7/test/spec_session_abstract_session_hash.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_session_abstract_session_hash.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/test/spec_session_abstract_session_hash.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/test/spec_session_abstract_session_hash.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_session_abstract_session_hash.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_session_abstract_session_hash.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_session_abstract_session_hash.rb