Skip to content

Commit 0b79b0c

Browse files
authored
fix: dialyzer typespec issue with partial env (elixir-tesla#727)
chore: add partial_env to test module
1 parent dd9f0a1 commit 0b79b0c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

lib/tesla/test.ex

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ defmodule Tesla.Test do
6969
@spec html(%Tesla.Env{}, binary) :: %Tesla.Env{}
7070
def html(%Tesla.Env{} = env, body) when is_binary(body) do
7171
env
72-
|> Tesla.put_body(body)
73-
|> Tesla.put_headers([{"content-type", "text/html; charset=utf-8"}])
72+
|> put_body(body)
73+
|> put_headers([{"content-type", "text/html; charset=utf-8"}])
7474
end
7575

7676
@doc """
@@ -91,8 +91,8 @@ defmodule Tesla.Test do
9191
body = encode!(body, "application/json")
9292

9393
env
94-
|> Tesla.put_body(body)
95-
|> Tesla.put_headers([{"content-type", "application/json; charset=utf-8"}])
94+
|> put_body(body)
95+
|> put_headers([{"content-type", "application/json; charset=utf-8"}])
9696
end
9797

9898
@doc """
@@ -108,8 +108,8 @@ defmodule Tesla.Test do
108108
@spec text(%Tesla.Env{}, binary) :: %Tesla.Env{}
109109
def text(%Tesla.Env{} = env, body) when is_binary(body) do
110110
env
111-
|> Tesla.put_body(body)
112-
|> Tesla.put_headers([{"content-type", "text/plain; charset=utf-8"}])
111+
|> put_body(body)
112+
|> put_headers([{"content-type", "text/plain; charset=utf-8"}])
113113
end
114114

115115
@doc """
@@ -271,4 +271,16 @@ defmodule Tesla.Test do
271271
adapter
272272
end
273273
end
274+
275+
defp put_body(%Tesla.Env{} = env, body) do
276+
%{env | body: body}
277+
end
278+
279+
defp put_headers(%Tesla.Env{headers: nil} = env, headers) when is_list(headers) do
280+
%{env | headers: headers}
281+
end
282+
283+
defp put_headers(%Tesla.Env{} = env, headers) when is_list(headers) do
284+
%{env | headers: env.headers ++ headers}
285+
end
274286
end

0 commit comments

Comments
 (0)