Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deps and test with Elixir 1.16 #719

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## v1.0.35 (TBA)

Handles Elixir 1.16 deprecations.

### Enhancements

* [`Pow.Ecto.Schema.Changeset`] Now handles MFA for `:password_hash_verify`
Expand Down
13 changes: 9 additions & 4 deletions lib/mix/pow.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Mix.Pow do
@moduledoc """
Utilities module for mix tasks.
"""
alias Mix.{Dep, Project}
alias Mix.{Dep.Converger, Project}

@doc """
Raises an exception if the project is an umbrella app.
Expand All @@ -22,7 +22,7 @@ defmodule Mix.Pow do
@spec ensure_dep!(binary(), atom(), OptionParser.argv()) :: :ok
def ensure_dep!(task, dep, _args) do
[]
|> Dep.load_on_environment()
|> __dependencies__()
|> top_level_dep_in_deps?(dep)
|> case do
true ->
Expand All @@ -33,12 +33,17 @@ defmodule Mix.Pow do
end
end

@doc false
def __dependencies__(opts) do
Converger.converge(nil, nil, opts, &{&1, &2, &3}) |> elem(0)
end

@doc """
Raises an exception if application doesn't have Ecto as dependency.
"""
@spec ensure_ecto!(binary(), OptionParser.argv()) :: :ok
def ensure_ecto!(task, _args) do
deps = Dep.load_on_environment([])
deps = __dependencies__([])

cond do
top_level_dep_in_deps?(deps, :ecto) -> :ok
Expand All @@ -60,7 +65,7 @@ defmodule Mix.Pow do
@spec ensure_phoenix!(binary(), OptionParser.argv()) :: :ok
def ensure_phoenix!(task, _args) do
[]
|> Dep.load_on_environment()
|> __dependencies__()
|> top_level_dep_in_deps?(:phoenix)
|> case do
true -> :ok
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/ecto/pow.ecto.gen.schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ defmodule Mix.Tasks.Pow.Ecto.Gen.Schema do
defp dir_name(schema_name) do
schema_name
|> String.split(".")
|> Enum.slice(0..-2)
|> Enum.slice(0..-2//1)
|> Enum.join(".")
|> Macro.underscore()
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pow/ecto/schema/migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ defmodule Pow.Ecto.Schema.Migration do
:ok = Enum.each(attrs, &validate!/1)

attrs
|> Enum.reject(&is_virtual?/1)
|> Enum.reject(&virtual?/1)
|> Enum.map(&normalize_migration_options/1)
|> Enum.map(&to_migration_attr/1)
end
Expand All @@ -99,7 +99,7 @@ defmodule Pow.Ecto.Schema.Migration do
"""
end

defp is_virtual?({_name, _type, field_options, _migration_options}), do: Keyword.get(field_options, :virtual, false)
defp virtual?({_name, _type, field_options, _migration_options}), do: Keyword.get(field_options, :virtual, false)

defp normalize_migration_options({name, type, field_options, migration_options}) do
options =
Expand Down
14 changes: 13 additions & 1 deletion lib/pow/phoenix/mailer/template.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ defmodule Pow.Phoenix.Mailer.Template do
quote do
use Pow.Phoenix.Mailer.Component
import unquote(__MODULE__)
import Phoenix.HTML.{Link, Tag}

# Credo will complain about unless statement but we want this first
# credo:disable-for-next-line
unless Pow.dependency_vsn_match?(:phoenix, "< 1.7.0") do
quote do
use Phoenix.Component
end
else
# TODO: Remove when Phoenix 1.7 is required
quote do
import Phoenix.HTML.{Form, Link}
end
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Pow.MixProject do
[
{:ecto, "~> 2.2 or ~> 3.0"},
{:phoenix, ">= 1.3.0 and < 1.8.0"},
{:phoenix_html, ">= 2.0.0 and < 4.0.0"},
{:phoenix_html, ">= 2.0.0 and < 5.0.0"},
{:plug, ">= 1.5.0 and < 2.0.0", optional: true},
{:phoenix_live_view, ">= 0.18.0", optional: true},

Expand Down
44 changes: 22 additions & 22 deletions mix.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/mix/tasks/ecto/pow.ecto.gen.migration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ defmodule Mix.Tasks.Pow.Ecto.Gen.MigrationTest do
File.cd!(context.tmp_path, fn ->
Migration.run(@options)

assert_received {:mix_shell, :info, ["* creating ./migrations"]}
assert_received {:mix_shell, :info, ["* creating ./migrations/" <> _]}
assert_received {:mix_shell, :info, ["* creating" <> _]}
assert_received {:mix_shell, :info, ["* creating" <> _]}

assert [migration_file] = File.ls!(@migrations_path)
assert String.match?(migration_file, ~r/^\d{14}_create_users\.exs$/)
Expand Down
2 changes: 1 addition & 1 deletion test/mix/tasks/ecto/pow.ecto.install_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defmodule Mix.Tasks.Pow.Ecto.InstallTest do

Mix.Project.in_project(:missing_top_level_ecto_dep, ".", fn _ ->
# Insurance that we do test for top level ecto inclusion
assert Enum.any?(Mix.Dep.load_on_environment([]), fn
assert Enum.any?(Mix.Pow.__dependencies__([]), fn
%{app: :ecto_sql} -> true
_ -> false
end), "Ecto not loaded by dependency"
Expand Down
2 changes: 1 addition & 1 deletion test/mix/tasks/phoenix/pow.phoenix.install_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ defmodule Mix.Tasks.Pow.Phoenix.InstallTest do

Mix.Project.in_project(:missing_top_level_phoenix_dep, ".", fn _ ->
# Insurance that we do test for top level phoenix inclusion
assert Enum.any?(Mix.Dep.load_on_environment([]), fn
assert Enum.any?(Mix.Pow.__dependencies__([]), fn
%{app: :phoenix} -> true
_ -> false
end), "Phoenix not loaded by dependency"
Expand Down
Loading