Open nelsonic opened 5 years ago
After reading: https://hexdocs.pm/ecto_sql/Ecto.Adapters.SQL.Sandbox.html
Add the following code to the top of the test:
setup do
# Explicitly get a connection before each test
:ok = Ecto.Adapters.SQL.Sandbox.checkout(YourApp.Repo)
end
Now the test runs as expected:
Finished in 0.05 seconds
1 test, 0 failures
@nelsonic
I wonder if the intended path is to
use MyApp.Datacase
instead of use ExUnit.Case
as defined in test/support/data_case.ex
Had this problem myself what do you think?
EDIT: oops I guess its model_case.ex
for older versions of phoenix
@HoffsMH good thinking! 💡
Thank's @nelsonic !
I wonder if the intended path is to
use MyApp.Datacase
instead ofuse ExUnit.Case
as defined intest/support/data_case.ex
Because I ran into an intermittent error with this, it's worth noting: when you're implicitly affecting a repo controlled by another module in a test, you'll still need to do an explicit checkout(..)
.
When attempting to create/run a test that inserts data:
attempting to run it with the command:
I get the following error:
Obviously the
Useragent.insert
works when I run the appmix phx.server
... But the test does not run because it does not have ownership of the connection ... 😞