Skip to content

Instantly share code, notes, and snippets.

@tokafish
Last active February 26, 2016 17:40
Show Gist options
  • Save tokafish/b17a9a78bf9b188c874f to your computer and use it in GitHub Desktop.
Save tokafish/b17a9a78bf9b188c874f to your computer and use it in GitHub Desktop.
defmodule Phoenix.Ecto.SQL.Sandbox do
# ...
def call(conn, sandbox) do
conn |> fetch_cookies |> allow_sandbox_access(sandbox)
end
defp allow_sandbox_access(%{req_cookies: %{@cookie_name => configuration}} = conn, sandbox) do
[pid_string,repo_string] = configuration |> URI.decode |> String.split("|")
owner = to_pid(pid_string)
repo = String.to_atom(repo_string)
Ecto.Adapters.SQL.Sandbox.allow(repo, owner, self())
conn
end
defp allow_sandbox_access(conn, _sandbox), do: conn
defp to_pid(string) do
string |> String.to_char_list |> :erlang.list_to_pid
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment