From a2d1ff9b897c7424886106685bd017a7d565704a Mon Sep 17 00:00:00 2001 From: shibao Date: Mon, 28 Mar 2022 23:05:12 -0400 Subject: [PATCH] fix credo --- .credo.exs | 14 +++++++------- lib/cannery/accounts.ex | 10 +++++----- lib/cannery/accounts/user.ex | 2 +- lib/cannery/ammo.ex | 2 +- lib/cannery/containers.ex | 2 +- lib/cannery/release.ex | 4 ++-- lib/cannery/repo/migrator.ex | 4 ++-- lib/cannery_web.ex | 7 +++++++ lib/cannery_web/live/ammo_group_live/show.ex | 4 ++-- lib/cannery_web/live/ammo_type_live/show.ex | 4 ++-- lib/cannery_web/live/container_live/show.ex | 4 ++-- lib/cannery_web/live/home_live.ex | 2 +- lib/cannery_web/live/invite_live/index.ex | 2 +- lib/cannery_web/views/email_view.ex | 3 +-- lib/cannery_web/views/error_view.ex | 2 +- test/cannery/accounts_test.exs | 8 ++++---- test/cannery_web/controllers/user_auth_test.exs | 2 +- .../user_confirmation_controller_test.exs | 3 +-- test/cannery_web/live/ammo_group_live_test.exs | 14 +++++++------- test/cannery_web/live/ammo_type_live_test.exs | 6 +++--- test/cannery_web/live/container_live_test.exs | 6 +++--- test/cannery_web/live/invite_live_test.exs | 4 ++-- test/cannery_web/live/range_live_test.exs | 4 ++-- test/cannery_web/live/tag_live_test.exs | 4 ++-- test/cannery_web/views/error_view_test.exs | 5 ++--- test/support/conn_case.ex | 1 + test/support/data_case.ex | 8 +++----- 27 files changed, 67 insertions(+), 64 deletions(-) diff --git a/.credo.exs b/.credo.exs index 7bc729a1..d6ee0bb4 100644 --- a/.credo.exs +++ b/.credo.exs @@ -157,17 +157,17 @@ # # Controversial and experimental checks (opt-in, just replace `false` with `[]`) # - {Credo.Check.Consistency.MultiAliasImportRequireUse, false}, - {Credo.Check.Consistency.UnusedVariableNames, false}, + {Credo.Check.Consistency.MultiAliasImportRequireUse, []}, + {Credo.Check.Consistency.UnusedVariableNames, [force: :meaningful]}, {Credo.Check.Design.DuplicatedCode, false}, {Credo.Check.Readability.AliasAs, false}, {Credo.Check.Readability.BlockPipe, false}, {Credo.Check.Readability.ImplTrue, false}, {Credo.Check.Readability.MultiAlias, false}, - {Credo.Check.Readability.SeparateAliasRequire, false}, + {Credo.Check.Readability.SeparateAliasRequire, []}, {Credo.Check.Readability.SinglePipe, false}, {Credo.Check.Readability.Specs, false}, - {Credo.Check.Readability.StrictModuleLayout, false}, + {Credo.Check.Readability.StrictModuleLayout, []}, {Credo.Check.Readability.WithCustomTaggedTuple, false}, {Credo.Check.Refactor.ABCSize, false}, {Credo.Check.Refactor.AppendSingleItem, false}, @@ -176,9 +176,9 @@ {Credo.Check.Refactor.NegatedIsNil, false}, {Credo.Check.Refactor.PipeChainStart, false}, {Credo.Check.Refactor.VariableRebinding, false}, - {Credo.Check.Warning.LeakyEnvironment, false}, - {Credo.Check.Warning.MapGetUnsafePass, false}, - {Credo.Check.Warning.UnsafeToAtom, false} + {Credo.Check.Warning.LeakyEnvironment, []}, + {Credo.Check.Warning.MapGetUnsafePass, []}, + {Credo.Check.Warning.UnsafeToAtom, []} # # Custom checks can be created using `mix credo.gen.check`. diff --git a/lib/cannery/accounts.ex b/lib/cannery/accounts.ex index 454ef4a2..55c2c6bc 100644 --- a/lib/cannery/accounts.ex +++ b/lib/cannery/accounts.ex @@ -196,7 +196,7 @@ defmodule Cannery.Accounts do {:ok, _} <- Repo.transaction(user_email_multi(user, email, context)) do :ok else - _ -> :error + _error_tuple -> :error end end @@ -265,7 +265,7 @@ defmodule Cannery.Accounts do |> Repo.transaction() |> case do {:ok, %{user: user}} -> {:ok, user} - {:error, :user, changeset, _} -> {:error, changeset} + {:error, :user, changeset, _changes_so_far} -> {:error, changeset} end end @@ -372,7 +372,7 @@ defmodule Cannery.Accounts do {:ok, %{user: user}} <- Repo.transaction(confirm_user_multi(user)) do {:ok, user} else - _ -> :error + _error_tuple -> :error end end @@ -420,7 +420,7 @@ defmodule Cannery.Accounts do %User{} = user <- Repo.one(query) do user else - _ -> nil + _error_tuple -> nil end end @@ -444,7 +444,7 @@ defmodule Cannery.Accounts do |> Repo.transaction() |> case do {:ok, %{user: user}} -> {:ok, user} - {:error, :user, changeset, _} -> {:error, changeset} + {:error, :user, changeset, _changes_so_far} -> {:error, changeset} end end end diff --git a/lib/cannery/accounts/user.ex b/lib/cannery/accounts/user.ex index a22267a3..1ac4e966 100644 --- a/lib/cannery/accounts/user.ex +++ b/lib/cannery/accounts/user.ex @@ -171,7 +171,7 @@ defmodule Cannery.Accounts.User do Bcrypt.verify_pass(password, hashed_password) end - def valid_password?(_, _) do + def valid_password?(_invalid_user, _invalid_password) do Bcrypt.no_user_verify() false end diff --git a/lib/cannery/ammo.ex b/lib/cannery/ammo.ex index 827c848d..122adb4b 100644 --- a/lib/cannery/ammo.ex +++ b/lib/cannery/ammo.ex @@ -308,7 +308,7 @@ defmodule Cannery.Ammo do def get_used_count(%AmmoGroup{} = ammo_group) do ammo_group |> Repo.preload(:shot_groups) - |> Map.get(:shot_groups) + |> Map.fetch!(:shot_groups) |> Enum.map(fn %{count: count} -> count end) |> Enum.sum() end diff --git a/lib/cannery/containers.ex b/lib/cannery/containers.ex index 8baceba7..55e0b906 100644 --- a/lib/cannery/containers.ex +++ b/lib/cannery/containers.ex @@ -215,7 +215,7 @@ defmodule Cannery.Containers do def get_container_rounds!(%Container{} = container) do container |> Repo.preload(:ammo_groups) - |> Map.get(:ammo_groups) + |> Map.fetch!(:ammo_groups) |> Enum.map(fn %{count: count} -> count end) |> Enum.sum() end diff --git a/lib/cannery/release.ex b/lib/cannery/release.ex index c86ede1e..c5c9eec7 100644 --- a/lib/cannery/release.ex +++ b/lib/cannery/release.ex @@ -9,7 +9,7 @@ defmodule Cannery.Release do def rollback(repo, version) do load_app() - {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version)) + {:ok, _fun, _opts} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version)) end defp load_app do @@ -20,7 +20,7 @@ defmodule Cannery.Release do load_app() for repo <- Application.fetch_env!(@app, :ecto_repos) do - {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) + {:ok, _fun, _opts} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) end end end diff --git a/lib/cannery/repo/migrator.ex b/lib/cannery/repo/migrator.ex index 324d333a..f3cec946 100644 --- a/lib/cannery/repo/migrator.ex +++ b/lib/cannery/repo/migrator.ex @@ -6,11 +6,11 @@ defmodule Cannery.Repo.Migrator do use GenServer require Logger - def start_link(_) do + def start_link(_opts) do GenServer.start_link(__MODULE__, [], []) end - def init(_) do + def init(_opts) do migrate!() {:ok, nil} end diff --git a/lib/cannery_web.ex b/lib/cannery_web.ex index aeba852c..bdf581d3 100644 --- a/lib/cannery_web.ex +++ b/lib/cannery_web.ex @@ -71,6 +71,7 @@ defmodule CanneryWeb do quote do use Phoenix.Router + # credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse import Plug.Conn import Phoenix.Controller import Phoenix.LiveView.Router @@ -79,7 +80,9 @@ defmodule CanneryWeb do def channel do quote do + # credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse use Phoenix.Channel + # credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse import CanneryWeb.Gettext end end @@ -87,14 +90,18 @@ defmodule CanneryWeb do defp view_helpers do quote do # Use all HTML functionality (forms, tags, etc) + # credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse use Phoenix.HTML # Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc) + # credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse import Phoenix.LiveView.Helpers # Import basic rendering functionality (render, render_layout, etc) + # credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse import Phoenix.View + # credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse import CanneryWeb.{ErrorHelpers, Gettext, LiveHelpers, ViewHelpers} alias CanneryWeb.Router.Helpers, as: Routes end diff --git a/lib/cannery_web/live/ammo_group_live/show.ex b/lib/cannery_web/live/ammo_group_live/show.ex index c29a44b6..c019ce35 100644 --- a/lib/cannery_web/live/ammo_group_live/show.ex +++ b/lib/cannery_web/live/ammo_group_live/show.ex @@ -44,7 +44,7 @@ defmodule CanneryWeb.AmmoGroupLive.Show do @impl true def handle_event( "delete", - _, + _params, %{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket ) do ammo_group |> Ammo.delete_ammo_group!(current_user) @@ -58,7 +58,7 @@ defmodule CanneryWeb.AmmoGroupLive.Show do @impl true def handle_event( "toggle_staged", - _, + _params, %{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket ) do {:ok, ammo_group} = diff --git a/lib/cannery_web/live/ammo_type_live/show.ex b/lib/cannery_web/live/ammo_type_live/show.ex index de312072..c71b9169 100644 --- a/lib/cannery_web/live/ammo_type_live/show.ex +++ b/lib/cannery_web/live/ammo_type_live/show.ex @@ -14,7 +14,7 @@ defmodule CanneryWeb.AmmoTypeLive.Show do end @impl true - def handle_params(%{"id" => id}, _, %{assigns: %{current_user: current_user}} = socket) do + def handle_params(%{"id" => id}, _params, %{assigns: %{current_user: current_user}} = socket) do ammo_type = Ammo.get_ammo_type!(id, current_user) socket = @@ -32,7 +32,7 @@ defmodule CanneryWeb.AmmoTypeLive.Show do @impl true def handle_event( "delete", - _, + _params, %{assigns: %{ammo_type: ammo_type, current_user: current_user}} = socket ) do %{name: ammo_type_name} = ammo_type |> Ammo.delete_ammo_type!(current_user) diff --git a/lib/cannery_web/live/container_live/show.ex b/lib/cannery_web/live/container_live/show.ex index 36ae5856..8bf74414 100644 --- a/lib/cannery_web/live/container_live/show.ex +++ b/lib/cannery_web/live/container_live/show.ex @@ -18,7 +18,7 @@ defmodule CanneryWeb.ContainerLive.Show do @impl true def handle_params( %{"id" => id}, - _, + _session, %{assigns: %{current_user: current_user}} = socket ) do {:noreply, socket |> render_container(id, current_user)} @@ -53,7 +53,7 @@ defmodule CanneryWeb.ContainerLive.Show do @impl true def handle_event( "delete_container", - _, + _params, %{assigns: %{container: container, current_user: current_user}} = socket ) do socket = diff --git a/lib/cannery_web/live/home_live.ex b/lib/cannery_web/live/home_live.ex index 8bdcfc8e..c5db4191 100644 --- a/lib/cannery_web/live/home_live.ex +++ b/lib/cannery_web/live/home_live.ex @@ -29,7 +29,7 @@ defmodule CanneryWeb.HomeLive do %{^query => vsn} -> {:noreply, redirect(socket, external: "https://hexdocs.pm/#{query}/#{vsn}")} - _ -> + _no_query -> {:noreply, socket |> put_flash(:error, "No dependencies found matching \"#{query}\"") diff --git a/lib/cannery_web/live/invite_live/index.ex b/lib/cannery_web/live/invite_live/index.ex index ce0d29de..8715e0f0 100644 --- a/lib/cannery_web/live/invite_live/index.ex +++ b/lib/cannery_web/live/invite_live/index.ex @@ -119,7 +119,7 @@ defmodule CanneryWeb.InviteLive.Index do end @impl true - def handle_event("copy_to_clipboard", _, socket) do + def handle_event("copy_to_clipboard", _params, socket) do prompt = dgettext("prompts", "Copied to clipboard") {:noreply, socket |> put_flash(:info, prompt)} end diff --git a/lib/cannery_web/views/email_view.ex b/lib/cannery_web/views/email_view.ex index 60056ae5..8cb0ebdf 100644 --- a/lib/cannery_web/views/email_view.ex +++ b/lib/cannery_web/views/email_view.ex @@ -2,7 +2,6 @@ defmodule CanneryWeb.EmailView do @moduledoc """ A view for email-related helper functions """ - alias CanneryWeb.{Endpoint, HomeLive} - use CanneryWeb, :view + alias CanneryWeb.{Endpoint, HomeLive} end diff --git a/lib/cannery_web/views/error_view.ex b/lib/cannery_web/views/error_view.ex index 978b4cd4..4073755a 100644 --- a/lib/cannery_web/views/error_view.ex +++ b/lib/cannery_web/views/error_view.ex @@ -8,7 +8,7 @@ defmodule CanneryWeb.ErrorView do case error_path do "404.html" -> dgettext("errors", "Not found") "401.html" -> dgettext("errors", "Unauthorized") - _ -> dgettext("errors", "Internal Server Error") + _other_template -> dgettext("errors", "Internal Server Error") end render("error.html", %{error_string: error_string}) diff --git a/test/cannery/accounts_test.exs b/test/cannery/accounts_test.exs index b6a59dba..93001e7e 100644 --- a/test/cannery/accounts_test.exs +++ b/test/cannery/accounts_test.exs @@ -304,9 +304,9 @@ defmodule Cannery.AccountsTest do end test "deletes all tokens for the given user", %{user: user} do - _ = Accounts.generate_user_session_token(user) + _token = Accounts.generate_user_session_token(user) - {:ok, _} = + {:ok, _user} = Accounts.update_user_password(user, valid_user_password(), %{ "password" => "new valid password" }) @@ -501,8 +501,8 @@ defmodule Cannery.AccountsTest do end test "deletes all tokens for the given user", %{user: user} do - _ = Accounts.generate_user_session_token(user) - {:ok, _} = Accounts.reset_user_password(user, %{"password" => "new valid password"}) + _token = Accounts.generate_user_session_token(user) + {:ok, _user} = Accounts.reset_user_password(user, %{"password" => "new valid password"}) refute Repo.get_by(UserToken, user_id: user.id) end end diff --git a/test/cannery_web/controllers/user_auth_test.exs b/test/cannery_web/controllers/user_auth_test.exs index b1fb1413..98e7bcb2 100644 --- a/test/cannery_web/controllers/user_auth_test.exs +++ b/test/cannery_web/controllers/user_auth_test.exs @@ -116,7 +116,7 @@ defmodule CanneryWeb.UserAuthTest do end test "does not authenticate if data is missing", %{conn: conn, current_user: current_user} do - _ = Accounts.generate_user_session_token(current_user) + _token = Accounts.generate_user_session_token(current_user) conn = UserAuth.fetch_current_user(conn, []) refute get_session(conn, :user_token) refute conn.assigns.current_user diff --git a/test/cannery_web/controllers/user_confirmation_controller_test.exs b/test/cannery_web/controllers/user_confirmation_controller_test.exs index e31ec620..0d645b69 100644 --- a/test/cannery_web/controllers/user_confirmation_controller_test.exs +++ b/test/cannery_web/controllers/user_confirmation_controller_test.exs @@ -5,8 +5,7 @@ defmodule CanneryWeb.UserConfirmationControllerTest do use CanneryWeb.ConnCase, async: true import CanneryWeb.Gettext - alias Cannery.Accounts - alias Cannery.Repo + alias Cannery.{Accounts, Repo} @moduletag :user_confirmation_controller_test diff --git a/test/cannery_web/live/ammo_group_live_test.exs b/test/cannery_web/live/ammo_group_live_test.exs index 24beaad2..b3de49ae 100644 --- a/test/cannery_web/live/ammo_group_live_test.exs +++ b/test/cannery_web/live/ammo_group_live_test.exs @@ -51,7 +51,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do # |> form("#ammo_group-form", ammo_group: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#ammo_group-form", ammo_group: @create_attrs) |> render_submit() @@ -75,7 +75,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do # |> form("#ammo_group-form", ammo_group: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#ammo_group-form", ammo_group: @create_attrs |> Map.put("multiplier", to_string(multiplier)) @@ -135,7 +135,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do # |> form("#shot_group-form", shot_group: @invalid_attrs) # |> render_change() =~ dgettext("errors", "is invalid") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#shot-group-form", shot_group: @shot_group_create_attrs) |> render_submit() @@ -158,7 +158,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do # |> form("#ammo_group-form", ammo_group: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#ammo_group-form", ammo_group: @update_attrs) |> render_submit() @@ -204,7 +204,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do # |> form("#ammo_group-form", ammo_group: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = show_live |> form("#ammo_group-form", ammo_group: @update_attrs) |> render_submit() @@ -226,7 +226,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do # |> form("#shot_group-form", shot_group: @invalid_attrs) # |> render_change() =~ dgettext("errors", "is invalid") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#shot-group-form", shot_group: @shot_group_create_attrs) |> render_submit() @@ -251,7 +251,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do # |> form("#shot_group-form", shot_group: @invalid_attrs) # |> render_change() =~ dgettext("errors", "is invalid") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#shot-group-form", shot_group: @shot_group_update_attrs) |> render_submit() diff --git a/test/cannery_web/live/ammo_type_live_test.exs b/test/cannery_web/live/ammo_type_live_test.exs index 946b94c3..7cf31085 100644 --- a/test/cannery_web/live/ammo_type_live_test.exs +++ b/test/cannery_web/live/ammo_type_live_test.exs @@ -62,7 +62,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do # |> form("#ammo_type-form", ammo_type: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#ammo_type-form", ammo_type: @create_attrs) |> render_submit() @@ -86,7 +86,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do # |> form("#ammo_type-form", ammo_type: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#ammo_type-form", ammo_type: @update_attrs) |> render_submit() @@ -128,7 +128,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do # |> form("#ammo_type-form", ammo_type: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = show_live |> form("#ammo_type-form", ammo_type: @update_attrs) |> render_submit() diff --git a/test/cannery_web/live/container_live_test.exs b/test/cannery_web/live/container_live_test.exs index 1836975e..437c0f8b 100644 --- a/test/cannery_web/live/container_live_test.exs +++ b/test/cannery_web/live/container_live_test.exs @@ -52,7 +52,7 @@ defmodule CanneryWeb.ContainerLiveTest do # |> form("#container-form", container: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#container-form", container: @create_attrs) |> render_submit() @@ -78,7 +78,7 @@ defmodule CanneryWeb.ContainerLiveTest do # |> form("#container-form", container: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#container-form", container: @update_attrs) |> render_submit() @@ -123,7 +123,7 @@ defmodule CanneryWeb.ContainerLiveTest do # |> form("#container-form", container: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = show_live |> form("#container-form", container: @update_attrs) |> render_submit() diff --git a/test/cannery_web/live/invite_live_test.exs b/test/cannery_web/live/invite_live_test.exs index 26bcda43..f8a4f535 100644 --- a/test/cannery_web/live/invite_live_test.exs +++ b/test/cannery_web/live/invite_live_test.exs @@ -40,7 +40,7 @@ defmodule CanneryWeb.InviteLiveTest do # |> form("#invite-form", invite: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#invite-form", invite: @create_attrs) |> render_submit() @@ -63,7 +63,7 @@ defmodule CanneryWeb.InviteLiveTest do # |> form("#invite-form", invite: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#invite-form", invite: @update_attrs) |> render_submit() diff --git a/test/cannery_web/live/range_live_test.exs b/test/cannery_web/live/range_live_test.exs index 888ea0ce..5f25f961 100644 --- a/test/cannery_web/live/range_live_test.exs +++ b/test/cannery_web/live/range_live_test.exs @@ -49,7 +49,7 @@ defmodule CanneryWeb.RangeLiveTest do # |> form("#shot_group-form", shot_group: @invalid_attrs) # |> render_change() =~ dgettext("errors", "is invalid") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#shot-group-form", shot_group: @create_attrs) |> render_submit() @@ -71,7 +71,7 @@ defmodule CanneryWeb.RangeLiveTest do # |> form("#shot_group-form", shot_group: @invalid_attrs) # |> render_change() =~ dgettext("errors", "is invalid") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#shot-group-form", shot_group: @update_attrs) |> render_submit() diff --git a/test/cannery_web/live/tag_live_test.exs b/test/cannery_web/live/tag_live_test.exs index adcf22b5..70747d1a 100644 --- a/test/cannery_web/live/tag_live_test.exs +++ b/test/cannery_web/live/tag_live_test.exs @@ -53,7 +53,7 @@ defmodule CanneryWeb.TagLiveTest do # |> form("#tag-form", tag: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#tag-form", tag: @create_attrs) |> render_submit() @@ -75,7 +75,7 @@ defmodule CanneryWeb.TagLiveTest do # |> form("#tag-form", tag: @invalid_attrs) # |> render_change() =~ dgettext("errors", "can't be blank") - {:ok, _, html} = + {:ok, _view, html} = index_live |> form("#tag-form", tag: @update_attrs) |> render_submit() diff --git a/test/cannery_web/views/error_view_test.exs b/test/cannery_web/views/error_view_test.exs index b37d9edf..5cffbce8 100644 --- a/test/cannery_web/views/error_view_test.exs +++ b/test/cannery_web/views/error_view_test.exs @@ -5,12 +5,11 @@ defmodule CanneryWeb.ErrorViewTest do use CanneryWeb.ConnCase, async: true import CanneryWeb.Gettext - - @moduletag :error_view_test - # Bring render/3 and render_to_string/3 for testing custom views import Phoenix.View + @moduletag :error_view_test + test "renders 404.html" do assert render_to_string(CanneryWeb.ErrorView, "404.html", []) =~ dgettext("errors", "Not found") diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 467826a2..f35a6fd6 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -25,6 +25,7 @@ defmodule CanneryWeb.ConnCase do # Import conveniences for testing with connections import Plug.Conn import Phoenix.ConnTest + # credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse import Cannery.Fixtures import CanneryWeb.ConnCase diff --git a/test/support/data_case.ex b/test/support/data_case.ex index a9022604..1302072c 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -22,10 +22,8 @@ defmodule Cannery.DataCase do alias Cannery.Repo import Ecto - import Ecto.Changeset - import Ecto.Query - import Cannery.DataCase - import Cannery.Fixtures + import Ecto.{Changeset, Query} + import Cannery.{DataCase, Fixtures} end end @@ -45,7 +43,7 @@ defmodule Cannery.DataCase do """ def errors_on(changeset) do Ecto.Changeset.traverse_errors(changeset, fn {message, opts} -> - Regex.replace(~r"%{(\w+)}", message, fn _, key -> + Regex.replace(~r"%{(\w+)}", message, fn _content, key -> opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string() end) end)