From 9972299fc490c7db6525a6597ad89921f9661f2a Mon Sep 17 00:00:00 2001 From: shibao Date: Tue, 8 Feb 2022 23:58:54 -0500 Subject: [PATCH] gettext user session controller --- .../controllers/user_session_controller.ex | 4 ++-- priv/gettext/default.pot | 5 +++++ priv/gettext/errors.pot | 5 +++++ .../user_session_controller_test.exs | 20 +++++++++---------- .../cannery_web/live/ammo_group_live_test.exs | 3 +-- test/cannery_web/live/ammo_type_live_test.exs | 3 +-- test/cannery_web/live/home_live_test.exs | 2 +- test/cannery_web/live/invite_live_test.exs | 3 +-- test/cannery_web/live/tag_live_test.exs | 3 +-- 9 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/cannery_web/controllers/user_session_controller.ex b/lib/cannery_web/controllers/user_session_controller.ex index e790deb7..f18f2a79 100644 --- a/lib/cannery_web/controllers/user_session_controller.ex +++ b/lib/cannery_web/controllers/user_session_controller.ex @@ -14,13 +14,13 @@ defmodule CanneryWeb.UserSessionController do if user = Accounts.get_user_by_email_and_password(email, password) do UserAuth.log_in_user(conn, user, user_params) else - render(conn, "new.html", error_message: "Invalid email or password") + render(conn, "new.html", error_message: dgettext("errors", "Invalid email or password")) end end def delete(conn, _params) do conn - |> put_flash(:info, "Logged out successfully.") + |> put_flash(:info, gettext("Logged out successfully.")) |> UserAuth.log_out_user() end end diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 2574858a..f389e544 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -109,3 +109,8 @@ msgstr "" #: lib/cannery_web/templates/user_settings/edit.html.heex:3 msgid "Settings" msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/controllers/user_session_controller.ex:23 +msgid "Logged out successfully." +msgstr "" diff --git a/priv/gettext/errors.pot b/priv/gettext/errors.pot index 61c4a851..da9abeaa 100644 --- a/priv/gettext/errors.pot +++ b/priv/gettext/errors.pot @@ -152,3 +152,8 @@ msgstr[1] "" #: lib/cannery_web/templates/user_settings/edit.html.heex:58 msgid "Oops, something went wrong! Please check the errors below." msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/controllers/user_session_controller.ex:17 +msgid "Invalid email or password" +msgstr "" diff --git a/test/cannery_web/controllers/user_session_controller_test.exs b/test/cannery_web/controllers/user_session_controller_test.exs index 9042279e..c2b4a4b4 100644 --- a/test/cannery_web/controllers/user_session_controller_test.exs +++ b/test/cannery_web/controllers/user_session_controller_test.exs @@ -1,8 +1,10 @@ defmodule CanneryWeb.UserSessionControllerTest do use CanneryWeb.ConnCase, async: true - + import CanneryWeb.Gettext import Cannery.AccountsFixtures + @moduletag :user_session_controller + setup do %{user: user_fixture()} end @@ -11,9 +13,8 @@ defmodule CanneryWeb.UserSessionControllerTest do test "renders log in page", %{conn: conn} do conn = get(conn, Routes.user_session_path(conn, :new)) response = html_response(conn, 200) - assert response =~ "

Log in

" - assert response =~ "Log in" - assert response =~ "Register" + assert response =~ dgettext("actions", "Log in") + assert response =~ dgettext("actions", "Register") end test "redirects if already logged in", %{conn: conn, user: user} do @@ -36,8 +37,7 @@ defmodule CanneryWeb.UserSessionControllerTest do conn = get(conn, "/") response = html_response(conn, 200) assert response =~ user.email - assert response =~ "Settings" - assert response =~ "Log out" + assert response =~ dgettext("prompts", "Are you sure you want to log out?") end test "logs the user in with remember me", %{conn: conn, user: user} do @@ -75,8 +75,8 @@ defmodule CanneryWeb.UserSessionControllerTest do }) response = html_response(conn, 200) - assert response =~ "

Log in

" - assert response =~ "Invalid email or password" + assert response =~ dgettext("actions", "Log in") + assert response =~ dgettext("errors", "Invalid email or password") end end @@ -85,14 +85,14 @@ defmodule CanneryWeb.UserSessionControllerTest do conn = conn |> log_in_user(user) |> delete(Routes.user_session_path(conn, :delete)) assert redirected_to(conn) == "/" refute get_session(conn, :user_token) - assert get_flash(conn, :info) =~ "Logged out successfully" + assert get_flash(conn, :info) =~ gettext("Logged out successfully") end test "succeeds even if the user is not logged in", %{conn: conn} do conn = delete(conn, Routes.user_session_path(conn, :delete)) assert redirected_to(conn) == "/" refute get_session(conn, :user_token) - assert get_flash(conn, :info) =~ "Logged out successfully" + assert get_flash(conn, :info) =~ gettext("Logged out successfully") end end end diff --git a/test/cannery_web/live/ammo_group_live_test.exs b/test/cannery_web/live/ammo_group_live_test.exs index ae6c5281..cb7903ef 100644 --- a/test/cannery_web/live/ammo_group_live_test.exs +++ b/test/cannery_web/live/ammo_group_live_test.exs @@ -1,8 +1,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do use CanneryWeb.ConnCase - import Phoenix.LiveViewTest - + import CanneryWeb.Gettext alias Cannery.Ammo @create_attrs %{count: 42, notes: "some notes", price_paid: 120.5} diff --git a/test/cannery_web/live/ammo_type_live_test.exs b/test/cannery_web/live/ammo_type_live_test.exs index 51eb0277..00b5514b 100644 --- a/test/cannery_web/live/ammo_type_live_test.exs +++ b/test/cannery_web/live/ammo_type_live_test.exs @@ -1,8 +1,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do use CanneryWeb.ConnCase - import Phoenix.LiveViewTest - + import CanneryWeb.Gettext alias Cannery.Ammo @create_attrs %{ diff --git a/test/cannery_web/live/home_live_test.exs b/test/cannery_web/live/home_live_test.exs index dc58ff2a..43e3df0b 100644 --- a/test/cannery_web/live/home_live_test.exs +++ b/test/cannery_web/live/home_live_test.exs @@ -1,7 +1,7 @@ defmodule CanneryWeb.HomeLiveTest do use CanneryWeb.ConnCase - import Phoenix.LiveViewTest + import CanneryWeb.Gettext test "disconnected and connected render", %{conn: conn} do {:ok, home_live, disconnected_html} = live(conn, "/") diff --git a/test/cannery_web/live/invite_live_test.exs b/test/cannery_web/live/invite_live_test.exs index 838817aa..5d1556d3 100644 --- a/test/cannery_web/live/invite_live_test.exs +++ b/test/cannery_web/live/invite_live_test.exs @@ -1,8 +1,7 @@ defmodule CanneryWeb.InviteLiveTest do use CanneryWeb.ConnCase - import Phoenix.LiveViewTest - + import CanneryWeb.Gettext alias Cannery.Invites @create_attrs %{name: "some name", token: "some token"} diff --git a/test/cannery_web/live/tag_live_test.exs b/test/cannery_web/live/tag_live_test.exs index 63e5a5c4..62104f8b 100644 --- a/test/cannery_web/live/tag_live_test.exs +++ b/test/cannery_web/live/tag_live_test.exs @@ -1,8 +1,7 @@ defmodule CanneryWeb.TagLiveTest do use CanneryWeb.ConnCase - import Phoenix.LiveViewTest - + import CanneryWeb.Gettext alias Cannery.Tags @create_attrs %{