germsvel / phoenix_test

MIT License
146 stars 20 forks source link

Documentation: Add mentions for other Phoenix supported DBs #30

Closed sodapopcan closed 7 months ago

sodapopcan commented 7 months ago

I thought it would be good for the documentation to call out configuration for the other databases supported by phx_new.

For SQLite my setup looks like this:

setup tags do
  MyApp.DataCase.setup_sandbox(tags)

  {:ok, conn: Phoenix.ConnTest.build_conn()}
end

I'm creating this as an issue and not as a PR since I've never used MySQL or MSSQL with Phoenix and am not 100% sure what would be appropriate. I'm also not even sure if I'm missing something or am doing too much or too little for SQLite (though what I have is working).

Thanks for PhoenixTest!

germsvel commented 7 months ago

@sodapopcan thanks for opening an issue. My guess is that your DataCase.setup_sandbox/1 is doing the same thing I suggest doing in PhoenixTest docs:

    pid = Ecto.Adapters.SQL.Sandbox.start_owner!(MyApp.Repo, shared: not tags[:async])
    on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)

Can you see your DataCase and confirm if that's the case or if you're doing something else?

SQL.Sandbox is Ecto's Sandbox to use in tests, and I think it should work no matter what DB you're using. (I grabbed that code from Phoenix's generated DataCase for an app with PostgreSQL.)

sodapopcan commented 7 months ago

Oh my, this is embarrassing. This has turned out not to be a problem at all. I clearly had a bug (my guess is that I didn't change MyApp) and I ended up looking ConnCase to see what I thought would be the fix. I even created apps for MySQL and MSSQL but only looked at ConnCase. Oh boy. I was very excited to get started PhoenixTest and hit a couple of problems so I rushed to find a fix and I usually like to document these gotchas.

Thanks and sorry for the false alarm!