From b122c4d44f3958600706e43e9500d55562864521 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Mon, 19 Feb 2018 11:02:13 -0500 Subject: [PATCH] Games list shows opponent --- lib/chess/store/game.ex | 1 + lib/chess_web/templates/game/index.html.eex | 5 ++++- test/features/games_test.exs | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/chess/store/game.ex b/lib/chess/store/game.ex index 636c72c..7b92c12 100644 --- a/lib/chess/store/game.ex +++ b/lib/chess/store/game.ex @@ -37,6 +37,7 @@ defmodule Chess.Store.Game do def for_user(query, user) do query |> where([game], user_id: ^user.id) + |> preload(:opponent) end def ordered(query) do diff --git a/lib/chess_web/templates/game/index.html.eex b/lib/chess_web/templates/game/index.html.eex index c9f4c7c..71aafb7 100644 --- a/lib/chess_web/templates/game/index.html.eex +++ b/lib/chess_web/templates/game/index.html.eex @@ -5,7 +5,10 @@ <%= for game <- @games do %> - <%= link "Started on #{Timex.format!(game.inserted_at, "%b %e at %I:%M %P", :strftime)}", to: game_path(@conn, :show, game), class: "btn btn-default btn-xs" %> + <%= link "Game with #{game.opponent.username}", to: game_path(@conn, :show, game), class: "btn btn-default btn-xs" %> + + + Started on <%= Timex.format!(game.inserted_at, "%b %e at %I:%M %P", :strftime) %> <%= link "Delete", to: game_path(@conn, :delete, game), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %> diff --git a/test/features/games_test.exs b/test/features/games_test.exs index c70c751..728b88c 100644 --- a/test/features/games_test.exs +++ b/test/features/games_test.exs @@ -41,6 +41,7 @@ defmodule Chess.GamesTest do session |> assert_has(css(".table tr", count: 1)) + |> assert_has(link("Game with urbosa")) end test "can move a piece", %{session: session} do