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
Popular in Questions
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
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
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
I would like to know what is the best IDE for elixir development?
New
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
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
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
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
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
I would like to know what is the best IDE for elixir development?
New
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
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
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










