prop/lib/microwaveprop_web/sandbox_hook.ex
Graham McIntire 933397d246
Some checks failed
Build and Push / Build and Push Docker Image (push) Failing after 6m41s
chore: remove all APRS-related code and fix credo issues
- 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
2026-08-04 12:12:28 -05:00

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