I wrote a little plug that accepts a list of actions as options. When the action that is currently called is in this list, the plug will behave differently.
For testing this I need to set the action in my unit tests. Is this possible? I didn't find anything in the docs.
This is the short example given in the Docs of Plug.
defmodule MyPlugTest do
use ExUnit.Case, async: true
use Plug.Test
@opts AppRouter.init([])
test "returns hello world" do
# Create a test connection
conn = conn(:get, "/hello")
# Invoke the plug
conn = AppRouter.call(conn, @opts)
# Assert the response and status
assert conn.state == :sent
assert conn.status == 200
assert conn.resp_body == "world"
end
end
conn = put_private(conn, :phoenix_action, :action_name)
(replace :action_name with the action's name)? – Dogbertexcept: [:create, :new]
into the plug, it shouldn't do some checks when the action is either:create
or:new
. So for testing this I need to be able to call a specific action in my tests. – Ole Spaarmann