From ec07e087bcef49c9d2766df3c0ad9e6767720013 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Wed, 21 Feb 2018 23:31:57 +0300 Subject: [PATCH] Make user bio optional --- lib/pleroma/user.ex | 6 +++--- test/user_test.exs | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 81cec8265..59f6340b8 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -93,7 +93,7 @@ defmodule Pleroma.User do |> cast(params, [:bio, :name]) |> unique_constraint(:nickname) |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) - |> validate_length(:bio, min: 1, max: 1000) + |> validate_length(:bio, max: 1000) |> validate_length(:name, min: 1, max: 100) end @@ -119,13 +119,13 @@ defmodule Pleroma.User do def register_changeset(struct, params \\ %{}) do changeset = struct |> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation]) - |> validate_required([:bio, :email, :name, :nickname, :password, :password_confirmation]) + |> validate_required([:email, :name, :nickname, :password, :password_confirmation]) |> validate_confirmation(:password) |> unique_constraint(:email) |> unique_constraint(:nickname) |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) |> validate_format(:email, @email_regex) - |> validate_length(:bio, min: 1, max: 1000) + |> validate_length(:bio, max: 1000) |> validate_length(:name, min: 1, max: 100) if changeset.valid? do diff --git a/test/user_test.exs b/test/user_test.exs index 0c87b778c..6bfdfe1bf 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -101,13 +101,14 @@ defmodule Pleroma.UserTest do email: "email@example.com" } - test "it requires a bio, email, name, nickname and password" do + test "it requires an email, name, nickname and password, bio is optional" do @full_user_data |> Map.keys |> Enum.each(fn (key) -> params = Map.delete(@full_user_data, key) changeset = User.register_changeset(%User{}, params) - assert changeset.valid? == false + + assert (if key == :bio, do: changeset.valid?, else: not changeset.valid?) end) end