Phoenix Upgrade导致put_req_header缺少函数子句

时间:2016-01-02 04:34:06

标签: elixir phoenix-framework

我最近升级到凤凰1.1.0并且测试过去的代码现在抛出错误。测试代码是:

  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

我现在得到的错误是:

** (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)

我尝试将导入Plug.Conn 别名Plug.Conn 添加到文件顶部,但这并没有改变任何内容。我是Phoenix / Elixir初学者,所以我不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:2)

根据堆栈跟踪,您正在调用put_req_header(%Conn{}, "unique_code", nil),其中值必须始终为二进制。我假设您提供的测试用例是真实的简化版本,也许您正在调用code.id(这是零)?仔细检查那里。