Some checks failed
Build and Push / Build and Push Docker Image (push) Failing after 6m41s
- Delete Microwaveprop.Aprs, AprsRepo, Aprs.PathParser modules - Delete Mix.Tasks.Calibrate.Aprs144 mix task - Remove AprsRepo from application.ex children and config files - Remove APRS test files and sandbox references in test_helper - Fix credo nested-module alias suggestions in conn_case.ex
27 lines
1,007 B
Elixir
27 lines
1,007 B
Elixir
defmodule MicrowavepropWeb.SandboxHook do
|
|
@moduledoc """
|
|
Test-only `on_mount` hook that allows a LiveView's connected mount to
|
|
use the same Ecto Sandbox connection as the test that's driving it.
|
|
|
|
Only wired in when `:sql_sandbox` is set (see `config/test.exs` and
|
|
`MicrowavepropWeb.Endpoint`).
|
|
"""
|
|
import Phoenix.Component, only: [assign_new: 3]
|
|
import Phoenix.LiveView, only: [connected?: 1, get_connect_info: 2]
|
|
|
|
alias Phoenix.LiveView.Socket
|
|
|
|
@spec on_mount(atom(), map(), map(), Socket.t()) :: {:cont, Socket.t()}
|
|
def on_mount(:default, _params, _session, socket) do
|
|
socket =
|
|
assign_new(socket, :phoenix_ecto_sandbox, fn ->
|
|
if connected?(socket), do: get_connect_info(socket, :user_agent)
|
|
end)
|
|
|
|
result = Phoenix.Ecto.SQL.Sandbox.allow(socket.assigns.phoenix_ecto_sandbox, Ecto.Adapters.SQL.Sandbox)
|
|
|
|
IO.puts("DEBUG SandboxHook connected?=#{connected?(socket)} self=#{inspect(self())} allow_result=#{inspect(result)}")
|
|
|
|
{:cont, socket}
|
|
end
|
|
end
|