Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure adapter is set #717

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading