Skip to content

Commit

Permalink
Remove redix and add registration for fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
axelclark committed Mar 10, 2024
1 parent bf9bb22 commit 868fd86
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lib/ex338/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ defmodule Ex338.Accounts do
|> Repo.insert()
end

def register_user_for_fixture(attrs) do
%User{}
|> User.registration_fixture_changeset(attrs)
|> Repo.insert()
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking user changes.
Expand Down
11 changes: 10 additions & 1 deletion lib/ex338/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@ defmodule Ex338.Accounts.User do
"""
def registration_changeset(user, attrs, opts \\ []) do
user
|> cast(attrs, [:email, :password, :admin, :name])
|> cast(attrs, [:email, :password, :name])
|> validate_required([:name])
|> validate_email(opts)
|> validate_password(opts)
end

def registration_fixture_changeset(user, attrs, opts \\ []) do
user
|> cast(attrs, [:email, :password, :name, :admin, :slack_name, :confirmed_at])
|> validate_required([:name])
|> validate_email(opts)
|> validate_password(opts)
end
Expand Down
1 change: 0 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ defmodule Ex338.Mixfile do
{:phoenix_view, "~> 2.0"},
{:plug_cowboy, "~> 2.7"},
{:postgrex, "~> 0.17.4"},
{:redix, "~> 1.3.0"},
{:styler, "~> 0.11", only: [:dev, :test], runtime: false},
{:swoosh, "~> 1.15"},
{:telemetry_poller, "~> 0.4"},
Expand Down
2 changes: 1 addition & 1 deletion test/ex338/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ defmodule Ex338.AccountsTest do
describe "change_user_registration/2" do
test "returns a changeset" do
assert %Ecto.Changeset{} = changeset = Accounts.change_user_registration(%User{})
assert changeset.required == [:password, :email]
assert changeset.required == [:password, :email, :name]
end

test "allows fields to be set" do
Expand Down
2 changes: 1 addition & 1 deletion test/support/fixtures/accounts_fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Ex338.AccountsFixtures do
{:ok, user} =
attrs
|> valid_user_attributes()
|> Ex338.Accounts.register_user()
|> Ex338.Accounts.register_user_for_fixture()

user
end
Expand Down

0 comments on commit 868fd86

Please sign in to comment.