Skip to content

Commit

Permalink
if person is already logged in, redirect to /items/new form #71
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Oct 5, 2020
1 parent 94d408b commit 1dc6260
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/app_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions test/app_web/controllers/page_controller_test.exs
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1dc6260

Please sign in to comment.