Sha256: dc5e9b0ddf5cf957f366d71c52a4cbb6a5417734e8996878ddd0e717c5205a2b

Contents?: true

Size: 943 Bytes

Versions: 4

Compression:

Stored size: 943 Bytes

Contents

# frozen_string_literal: true

require "test_helper"

class SessionTest < Minitest::Test
  test "returns nil for missing gid" do
    User.delete_all
    user = User.create!(password: "test", email: "john@example.com")
    session_store = {}

    SimpleAuth::Session.create(
      scope: "user",
      record: user,
      session: session_store
    )

    user.destroy!

    session = SimpleAuth::Session.create(
      scope: "user",
      session: session_store
    )

    assert_nil session.record
  end

  test "returns nil for missing gid (custom error)" do
    not_found_error = Class.new(StandardError)
    SimpleAuth::Session.record_not_found_exceptions << not_found_error

    GlobalID::Locator.use :foo do |gid|
      raise not_found_error, "record not found: #{gid}"
    end

    session = SimpleAuth::Session.create(
      scope: "user",
      session: {user_id: "gid://foo/User/1234"}
    )

    assert_nil session.record
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
simple_auth-3.1.4 test/unit/session_test.rb
simple_auth-3.1.3 test/unit/session_test.rb
simple_auth-3.1.2 test/unit/session_test.rb
simple_auth-3.1.1 test/unit/session_test.rb