Reputation: 1390
I upgraded to Phoenix 1.1.0 recently and test code that used to pass is now throwing an error. The test code is:
test "/api call with invalid unique_code gets an error code", %{conn: conn} do
conn = recycle(conn)
|> put_req_header("unique_code", "123")
|> put_req_header("domain", "cision.com")
conn = get conn, "/api/organizations/valid"
assert conn.status == 500
end
The error I'm getting now is:
** (FunctionClauseError) no function clause matching in Plug.Conn.put_req_header/3
stacktrace:
(plug) lib/plug/conn.ex:460: Plug.Conn.put_req_header(%Plug.Conn{adapter: {Plug.Adapters.Test.Conn, :...}, assigns: %{}, before_send: [], body_params: %Plug.Conn.Unfetched{aspect: :body_params}, cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false, host: "www.example.com", method: "GET", owner: #PID<0.293.0>, params: %Plug.Conn.Unfetched{aspect: :params}, path_info: [], peer: {{127, 0, 0, 1}, 111317}, port: 80, private: %{phoenix_recycled: true, plug_skip_csrf_protection: true}, query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies}, req_headers: [], request_path: "/", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}], scheme: :http, script_name: [], secret_key_base: nil, state: :unset, status: nil}, "unique_code", nil)
I tried to add a import Plug.Conn and alias Plug.Conn to the top of the file, but that didn't change anything. I'm a Phoenix/Elixir beginner so I'm not sure how to fix this.
Upvotes: 1
Views: 1246
Reputation: 8120
According to the stack trace, you are calling put_req_header(%Conn{}, "unique_code", nil)
, where the value must always be a binary. I'm assuming your provided test case was a simplified version of the real thing, and that maybe you are calling code.id
(which is nil)? Double check there.
Upvotes: 2