@@ -108,7 +108,7 @@ defmodule Phoenix.Ecto.SQL.Sandbox do
108108 {:cont, socket}
109109 end
110110 end
111-
111+
112112 Now, in your `my_app_web.ex` file, you can invoke this callback for all of your
113113 LiveViews if the sandbox configuration, defined at the beginning of the
114114 documentation, is enabled:
@@ -117,11 +117,11 @@ defmodule Phoenix.Ecto.SQL.Sandbox do
117117 quote do
118118 use Phoenix.LiveView
119119 # ...
120-
120+
121121 if Application.compile_env(:your_app, :sql_sandbox) do
122122 on_mount MyApp.LiveAcceptance
123123 end
124-
124+
125125 # ...
126126 end
127127 end
@@ -215,7 +215,8 @@ defmodule Phoenix.Ecto.SQL.Sandbox do
215215 header: Keyword . get ( opts , :header , "user-agent" ) ,
216216 path: get_path_info ( opts [ :at ] ) ,
217217 repos: List . wrap ( opts [ :repo ] ) ,
218- sandbox: session_opts [ :sandbox ] || Ecto.Adapters.SQL.Sandbox ,
218+ sandbox:
219+ session_opts [ :sandbox ] || { Ecto.Adapters.SQL.Sandbox , :allow , [ [ unallow_existing: true ] ] } ,
219220 session_opts: session_opts
220221 }
221222 end
@@ -339,8 +340,14 @@ defmodule Phoenix.Ecto.SQL.Sandbox do
339340 end
340341
341342 def allow ( % { repo: repo , owner: owner } , sandbox ) ,
342- do: Enum . each ( List . wrap ( repo ) , & sandbox . allow ( & 1 , owner , self ( ) , unallow_existing: true ) )
343+ do: Enum . each ( List . wrap ( repo ) , & allow_sandbox ( sandbox , & 1 , owner , self ( ) ) )
343344
344345 def allow ( % { } , _sandbox ) , do: :ok
345346 def allow ( nil , _sandbox ) , do: :ok
347+
348+ defp allow_sandbox ( { m , f , args } , repo , owner , pid ) ,
349+ do: apply ( m , f , [ repo , owner , pid | args ] )
350+
351+ defp allow_sandbox ( sandbox , repo , owner , pid ) when is_atom ( sandbox ) ,
352+ do: sandbox . allow ( repo , owner , pid )
346353end
0 commit comments