diff --git a/lib/app_web/controllers/page_controller.ex b/lib/app_web/controllers/page_controller.ex index 2941548d..dae442a7 100644 --- a/lib/app_web/controllers/page_controller.ex +++ b/lib/app_web/controllers/page_controller.ex @@ -1,7 +1,11 @@ defmodule AppWeb.PageController do use AppWeb, :controller - def index(conn, _params) do - render(conn, "index.html") + def index(conn, params) do + if Map.has_key?(conn.assigns, :person) do + redirect(conn, to: AppWeb.Router.Helpers.item_path(conn, :new, params)) + else + render(conn, "index.html") + end end end diff --git a/test/app_web/controllers/page_controller_test.exs b/test/app_web/controllers/page_controller_test.exs index 0aeb2083..e00cc64b 100644 --- a/test/app_web/controllers/page_controller_test.exs +++ b/test/app_web/controllers/page_controller_test.exs @@ -1,8 +1,18 @@ defmodule AppWeb.PageControllerTest do use AppWeb.ConnCase + import App.SetupHelpers test "GET /", %{conn: conn} do conn = get(conn, "/") assert html_response(conn, 200) =~ "effectiveness" end + + describe "GET / (homepage) when logged-in shows /items/new" do + setup [:person_login] + + test "redirects to the new item form form", %{conn: conn} do + conn = get(conn, "/") + assert html_response(conn, 302) =~ "redirected" + end + end end diff --git a/test/test_helper.exs b/test/test_helper.exs index 92e3d2a5..f3c1859e 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -40,4 +40,9 @@ defmodule AppTest do {:ok, conn: conn} end + + # create a random person and log them into the app + # def non_admin_login(conn) do + + # end end