1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Show opponent on game screen

This commit is contained in:
Daniel Barber 2018-02-19 13:27:17 -05:00
parent 9b47a85d8f
commit 8634d7aa9f
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
3 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -1,3 +1,5 @@
<h2>Game with <%= opponent(@conn, @game).username %></h2>
<p><%= link "Back to games", to: game_path(@conn, :index) %></p>
<div id="app" data-game-id="<%= @game.id %>">

View File

@ -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