diff --git a/lib/tesla.ex b/lib/tesla.ex index 92b04ee1..e2337134 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 e6e12397..8b649503 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"