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

Make :attr equivalent to required(:attr) in schemas #60

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

zachallaun
Copy link

Closes #59.

Also, I noticed that the code delete/purge logic in tests wasn't working in doctests (at least on Elixir 1.17.3), so 54b3b88 replaces it with a blanket "ignore duplicate module warnings" directive. If you'd prefer this not be there, or that it go in a different PR, I'm happy to remove it from this branch.

For example:

    schema do
      %{
        name: string(),
        email: string()
      }
    end

is now equivalent to:

    schema do
      %{
        required(:name) => string(),
        required(:email) => string()
      }
    end
Copy link
Owner

@solnic solnic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much! Seems like sorting in the test helper made some tests fail, but other than that - this looks great 💜

If you could fix the tests then I'd merge it and release it 🙂

@zachallaun
Copy link
Author

Seems like sorting in the test helper made some tests fail

I thought that too, but I think this is something else. The failures are in a doctest (not using the assert_errors from the test helper) and only on 25, so this is a problem with map sorting changing in OTP 26 (iirc).

There are a few solutions I can think of. Would appreciate your opinion on these.

  1. Exclude this doctest if System.otp_release() < "26". Kinda hacky, but doesn't require any code changes elsewhere.
  2. When returning {:error, errors}, always sort errors, perhaps on something like {error.path, error.text} (so that multiple errors for the same path are sorted deterministically).
  3. Rewrite the doctest in a way that doesn't care about order. So do something like {:error, errors} = UserContract.conform(...) and then %Drops.Validator.Messages.Error.Type{...} in errors. I personally like this option the least, since it makes the docs less clear and IMO doctests are just as important as docs than as tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Let :attr be equivalent to required(:attr) in schemas
2 participants