VadimSergeevich

VadimSergeevich

Controller test with Task

I have a controller in which after a successful insertion, I perform the background action with Task

case Repo.insert(changeset) do
  {:ok, payment} ->
    Task.start(__MODULE__, :after_change, [payment, params])
    conn
    |> # usual redirect 
end

def after_change(payment, params) do
  order = payment |> Repo.preload(:order) |> Map.get(:order)
  # some_work_with_order(order)
end

And I have test for this controller:

test "creates resource and redirects when data is valid", %{conn: conn} do
  order = insert(:order) # use ExMachina
  conn = post conn, payment_path(conn, :create), payment: %{:order_id, order.id}
  assert Repo.get_by(Payment, order_id: order.id)
end

But the test passes with an errors
with Myapp.ConnCase: disconnected: ** (DBConnection.ConnectionError) owner #PID<0.452.0> exited while client #PID<0.460.0> is still running with: shutdown
with Backoffice.ConnCase, async: true: сan not preload in #after_change, there are no more orders in the database and order == nil

I have read Ecto.Sandbox.FAQ, but I do not know how to apply it in my case, will be glad to any advice

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement