From 317a7d4f4e15a422c79af58332c6f84aea70fbff Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Mon, 21 Oct 2024 11:00:35 -0400 Subject: [PATCH] fix: ensure adapter is set (#717) --- lib/tesla.ex | 5 +++-- test/tesla_test.exs | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/tesla.ex b/lib/tesla.ex index 92b04ee1d..e2337134f 100644 --- a/lib/tesla.ex +++ b/lib/tesla.ex @@ -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 diff --git a/test/tesla_test.exs b/test/tesla_test.exs index e6e12397f..8b6495034 100644 --- a/test/tesla_test.exs +++ b/test/tesla_test.exs @@ -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 @@ -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"