Skip to content

Commit

Permalink
fix: ensure adapter is set (#717)
Browse files Browse the repository at this point in the history
  • Loading branch information
yordis authored Oct 21, 2024
1 parent 500b211 commit 317a7d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/tesla.ex
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ defmodule Tesla do
end

defp prepare(module, %{pre: pre, post: post} = client, options) do
env = struct(Env, options ++ [__module__: module, __client__: client])
stack = pre ++ module.__middleware__() ++ post ++ [effective_adapter(module, client)]
adapter = effective_adapter(module, client)
env = struct(Env, options ++ [__module__: module, __client__: %{client | adapter: adapter}])
stack = pre ++ module.__middleware__() ++ post ++ [adapter]
{env, stack}
end

Expand Down
7 changes: 6 additions & 1 deletion test/tesla_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule TeslaTest do
:ok
end

test "defauilt adapter" do
test "default adapter" do
assert Tesla.effective_adapter(EmptyClient) == {Tesla.Adapter.Httpc, :call, [[]]}
end

Expand All @@ -63,6 +63,11 @@ defmodule TeslaTest do
assert Tesla.effective_adapter(ModuleAdapterClient) == {Tesla.Mock, :call, [[]]}
end

test "ensure adapter is set" do
assert {:ok, response} = ModuleAdapterClient.request(url: "test")
assert response.__client__.adapter
end

test "execute module adapter" do
assert {:ok, response} = ModuleAdapterClient.request(url: "test")
assert response.url == "test/module/someopt"
Expand Down

0 comments on commit 317a7d4

Please sign in to comment.