Heres the error.
1) test checks if account is active authenticated?/2 halts if account is no longer active (Beffect.Plugs.AuthTest)
test/beffect/plug/auth_test.exs:7
** (ArgumentError) flash not fetched, call fetch_flash/2
code: |> Beffect.Plugs.Auth.authenticated?(%{})
stacktrace:
(phoenix) lib/phoenix/controller.ex:1228: Phoenix.Controller.get_flash/1
(phoenix) lib/phoenix/controller.ex:1210: Phoenix.Controller.put_flash/3
(beffect) lib/beffect/plugs/auth.ex:30: Beffect.Plugs.Auth.authenticated?/2
test/beffect/plug/auth_test.exs:17: (test)
FYI lib/beffect/plugs/auth.ex:30
is the puts_flash
heres the test
test "authenticated?/2 halts if account is no longer active" do
user = insert(:user, active: false)
conn = build_conn()
|> init_test_session(user_id: user.id)
|> assign(:current_user, user)
|> bypass_through(BeffectWeb.Router, :browser) # ? not sure if its really calling that pipeline
|> Beffect.Plugs.Auth.authenticated?(%{})
assert get_flash(conn, :error) =~ "Your account is no longer active"
assert redirected_to(conn) =~ "/login"
end
Heres Beffect.Plugs.Auth.authenticated?
def authenticated?(conn, _opts) do
cond do
conn.assigns.current_user && conn.assigns.current_user.active ->
conn
conn.assigns.current_user ->
assign(conn, :current_user, nil)
conn
|> put_flash(:error, "Your account is no longer active") # Setting the flash here
|> redirect(to: Helpers.session_path(conn, :new,origin_path: conn.request_path))
|> halt()
...
end
Heres the pipeline for :brower
pipeline :browser do
....
plug :fetch_flash # calling it here....
...
end
Also note that I IO.puts in the pipeline to see if its called and it looks as if it is being called.