Mateusz Urbański
Mateusz Urbański

Reputation: 7862

undefined function put_req_header/3

I have the following module in Phoenix app. This code is basically shared spec example. It looks like this:

defmodule TattooBackend.CurrentPasswordRequiredTest do
  @moduledoc """
  This module defines tests that are testing api current password requirement.
  """
  import Phoenix.ConnTest

  alias TattooBackend.Web.Router

  defmacro test_current_password_required_for(method, path_name, action) do
    quote do
      test "without current password", %{conn: conn} do
        method    = unquote(method)
        path_name = unquote(path_name)
        action    = unquote(action)
        account = insert(:account)

        assert make_unauthenticated_request(conn, @endpoint, method, path_name, action, account) == %{
          "error" => "Błędne hasło."
        }
      end
    end
  end

  def make_unauthenticated_request(conn, endpoint, method, path_name, action, account) do
    path = apply(Router.Helpers, path_name, [conn, action])

    conn
    |> put_req_header("authorization", "#{token(account)}")
    |> dispatch(endpoint, method, path, nil)
    |> json_response(422)
  end
end

When I run my specs it returns error:

** (CompileError) test/support/shared_tests/current_password_required.ex:28: undefined function put_req_header/3

How can I fix that?

Upvotes: 2

Views: 1166

Answers (1)

michalmuskala
michalmuskala

Reputation: 11288

The function is actually Plug.Conn.put_req_header/3 - you need to either use the full name or import the Plug.Conn module.

Upvotes: 7

Related Questions