Allow explicitly passing a dynamic repo to Ecto.Adapters.SQL.Sandbox.checkout/1#686
Allow explicitly passing a dynamic repo to Ecto.Adapters.SQL.Sandbox.checkout/1#686Gigitsu wants to merge 1 commit into
Ecto.Adapters.SQL.Sandbox.checkout/1#686Conversation
|
Integration tests are failing because a test expects an Could there be a better way to check if an atom represents a module? I could try using |
|
I assume your code is a bit more complex than this, right? How does your code look like? |
Yes, it's not much more complex, but it involves some code that might be internal to Ecto.
I ended up with this minimal setup: def setup_sandbox(tags) do
pid = SQL.Sandbox.start_owner!(repo_pid(), shared: not tags[:async])
on_exit(fn -> SQL.Sandbox.stop_owner(pid) end)
end
defp repo_pid do
GenServer.whereis(Hello.Repo.get_dynamic_repo())
endWe could also introduce a new |
|
The code that you pasted above is completely fine to me and only rely on public APIs. That’s definitely what I would recommend in this case. |
|
Ok, that seems fair to me. |
|
No need to be sorry, thank you for giving it a shot! |
As discussed in this Elixir Forum post, I encountered issues when testing with a dynamic repo.
This PR allows explicitly passing a dynamic repo to both
Ecto.Adapters.SQL.Sandbox.checkout/1andEcto.Adapters.SQL.Sandbox.start_owner!/1.With this change, I can change my
DataCasesetup as follows:This enables proper testing of dynamic repos without manual connection management.