diff --git a/lib/chess_web/controllers/game_controller.ex b/lib/chess_web/controllers/game_controller.ex index f2d8cbc..e690ac1 100644 --- a/lib/chess_web/controllers/game_controller.ex +++ b/lib/chess_web/controllers/game_controller.ex @@ -42,7 +42,10 @@ defmodule ChessWeb.GameController do end def show(conn, %{"id" => id}) do - game = Repo.get!(Game, id) + query = from(game in Game, preload: [:user, :opponent]) + game = + query + |> Repo.get!(id) render(conn, "show.html", game: game) end diff --git a/lib/chess_web/templates/game/show.html.eex b/lib/chess_web/templates/game/show.html.eex index a985599..0203eb8 100644 --- a/lib/chess_web/templates/game/show.html.eex +++ b/lib/chess_web/templates/game/show.html.eex @@ -1,3 +1,5 @@ +

Game with <%= opponent(@conn, @game).username %>

+

<%= link "Back to games", to: game_path(@conn, :index) %>

diff --git a/test/features/games_test.exs b/test/features/games_test.exs index 3ec28ca..778469a 100644 --- a/test/features/games_test.exs +++ b/test/features/games_test.exs @@ -22,6 +22,7 @@ defmodule Chess.GamesTest do |> click(button("Create game")) session + |> assert_has(css("h2", text: "Game with zelda")) |> assert_has(css(".board")) end @@ -56,6 +57,12 @@ defmodule Chess.GamesTest do session |> assert_has(css(".table tr", count: 1)) |> assert_has(link("Game with zelda")) + + session + |> click(link("Game with zelda")) + + session + |> assert_has(css("h2", text: "Game with zelda")) end test "can move a piece", %{session: session} do