diff --git a/lib/chess_web/controllers/game_controller.ex b/lib/chess_web/controllers/game_controller.ex index babca14..3a8a370 100644 --- a/lib/chess_web/controllers/game_controller.ex +++ b/lib/chess_web/controllers/game_controller.ex @@ -15,9 +15,9 @@ defmodule ChessWeb.GameController do conn |> current_user() |> Game.for_user() - |> Game.ordered + |> Game.ordered() |> preload([:user, :opponent]) - |> Repo.all + |> Repo.all() conn |> render("index.html", games: games, changeset: changeset) @@ -42,7 +42,7 @@ defmodule ChessWeb.GameController do |> Repo.preload(:user) |> Repo.preload(:opponent) ) - |> Mailer.deliver_later + |> Mailer.deliver_later() conn |> put_flash(:info, "Game created successfully.") @@ -53,7 +53,7 @@ defmodule ChessWeb.GameController do conn |> current_user() |> User.opponents() - |> Repo.all + |> Repo.all() conn |> render("new.html", changeset: changeset, opponents: opponents) diff --git a/lib/chess_web/templates/game/board.html.leex b/lib/chess_web/templates/game/board.html.leex index c5d3ede..caa9f78 100644 --- a/lib/chess_web/templates/game/board.html.leex +++ b/lib/chess_web/templates/game/board.html.leex @@ -37,5 +37,7 @@ <% end %> -
+
+ <%= states[@game.state] %> +
diff --git a/lib/chess_web/templates/password/edit.html.eex b/lib/chess_web/templates/password/edit.html.eex index 24e985b..35d1eb8 100644 --- a/lib/chess_web/templates/password/edit.html.eex +++ b/lib/chess_web/templates/password/edit.html.eex @@ -1,7 +1,7 @@

<%= gettext "Password" %>

- <%= form_for @changeset, password_path(@conn, :update), [class: "update-password"], fn f -> %> + <%= form_for @changeset, password_path(@conn, :update), [class: "update-password", novalidate: true], fn f -> %> <%= if @changeset.action do %>

diff --git a/lib/chess_web/templates/profile/edit.html.eex b/lib/chess_web/templates/profile/edit.html.eex index a8b335a..94cad6c 100644 --- a/lib/chess_web/templates/profile/edit.html.eex +++ b/lib/chess_web/templates/profile/edit.html.eex @@ -1,7 +1,7 @@

<%= gettext "Profile" %>

- <%= form_for @changeset, profile_path(@conn, :update), [class: "update-profile"], fn f -> %> + <%= form_for @changeset, profile_path(@conn, :update), [class: "update-profile", novalidate: true], fn f -> %> <%= if @changeset.action do %>

diff --git a/lib/chess_web/views/game_view.ex b/lib/chess_web/views/game_view.ex index e8e2d65..cc2303d 100644 --- a/lib/chess_web/views/game_view.ex +++ b/lib/chess_web/views/game_view.ex @@ -7,8 +7,8 @@ defmodule ChessWeb.GameView do def won_lost(conn, game) do if game_over?(game) && game.state == "checkmate" do - your_turn?(conn, game) && - gettext("You lost") || + (your_turn?(conn, game) && + gettext("You lost")) || gettext("You won") end end @@ -21,9 +21,12 @@ defmodule ChessWeb.GameView do cond do GameState.game_over?(game) -> states()[game.state] + your_turn?(conn, game) -> gettext("Your turn") - true -> nil + + true -> + nil end end @@ -34,16 +37,18 @@ defmodule ChessWeb.GameView do end def your_turn?(conn, game) do - player_colour(conn, game) == game.turn + conn + |> current_user() + |> player_colour(game) == game.turn end def player_colour(user, game) do - user.id == game.user_id && "white" || "black" + (user.id == game.user_id && "white") || "black" end def files(conn, game) do ranks(conn, game) - |> Enum.reverse + |> Enum.reverse() end def ranks(conn, game) do @@ -74,7 +79,7 @@ defmodule ChessWeb.GameView do %{ "checkmate" => gettext("Checkmate!"), "stalemate" => gettext("Stalemate"), - "check" => gettext("Check"), + "check" => gettext("Check") } end end diff --git a/test/chess_web/controllers/game_controller_test.exs b/test/chess_web/controllers/game_controller_test.exs index 27016ad..59b290f 100644 --- a/test/chess_web/controllers/game_controller_test.exs +++ b/test/chess_web/controllers/game_controller_test.exs @@ -60,7 +60,7 @@ defmodule ChessWeb.GameControllerTest do |> login(user) |> get(game_path(conn, :show, game)) - assert html_response(conn, 200) =~ "

" + assert html_response(conn, 200) =~ "
" end test "does not show a game if the user is not a player", %{conn: conn} do @@ -74,25 +74,25 @@ defmodule ChessWeb.GameControllerTest do conn |> login(other_user) - assert_error_sent 404, fn -> - get conn, game_path(conn, :show, game.id) - end + assert_error_sent(404, fn -> + get(conn, game_path(conn, :show, game.id)) + end) end test "renders page not found when id is nonexistent", %{conn: conn} do user = insert(:user) conn = login(conn, user) - assert_error_sent 404, fn -> - get conn, game_path(conn, :show, -1) - end + assert_error_sent(404, fn -> + get(conn, game_path(conn, :show, -1)) + end) end test "deletes game", %{conn: conn} do - game = Repo.insert! %Game{} + game = Repo.insert!(%Game{}) user = insert(:user) conn = login(conn, user) - conn = delete conn, game_path(conn, :delete, game) + conn = delete(conn, game_path(conn, :delete, game)) assert redirected_to(conn) == game_path(conn, :index) refute Repo.get(Game, game.id) end diff --git a/test/features/profile_test.exs b/test/features/profile_test.exs index b536821..eda2426 100644 --- a/test/features/profile_test.exs +++ b/test/features/profile_test.exs @@ -7,11 +7,12 @@ defmodule Chess.Features.ProfileTest do import Chess.AuthenticationHelpers test "user can update their details", %{session: session} do - user = insert(:user, %{ - name: "Link", - email: "link@hyrule.com", - password: "ilovezelda" - }) + user = + insert(:user, %{ + name: "Link", + email: "link@hyrule.com", + password: "ilovezelda" + }) session |> login(user.email, "ilovezelda") @@ -25,11 +26,12 @@ defmodule Chess.Features.ProfileTest do end test "name cannot be blank", %{session: session} do - user = insert(:user, %{ - name: "Link", - email: "link@hyrule.com", - password: "ilovezelda" - }) + user = + insert(:user, %{ + name: "Link", + email: "link@hyrule.com", + password: "ilovezelda" + }) session |> login(user.email, "ilovezelda") @@ -40,17 +42,16 @@ defmodule Chess.Features.ProfileTest do |> click(button("Update Profile")) session - |> assert_has( - css("[data-role='name-error']", text: "can't be blank") - ) + |> assert_has(css("[data-role='name-error']", text: "can't be blank")) end test "email cannot be blank", %{session: session} do - user = insert(:user, %{ - name: "Link", - email: "link@hyrule.com", - password: "ilovezelda" - }) + user = + insert(:user, %{ + name: "Link", + email: "link@hyrule.com", + password: "ilovezelda" + }) session |> login(user.email, "ilovezelda") @@ -61,8 +62,6 @@ defmodule Chess.Features.ProfileTest do |> click(button("Update Profile")) session - |> assert_has( - css("[data-role='email-error']", text: "can't be blank") - ) + |> assert_has(css("[data-role='email-error']", text: "can't be blank")) end end