CargoSense / vex

Data Validation for Elixir
MIT License
597 stars 60 forks source link

protocol Vex.Blank not implemented for ~N[2010-10-10 10:10:00.000000]. #50

Closed InteNs closed 4 years ago

InteNs commented 6 years ago

Hi, It seems that the Vex.Blank protocol is not implemented for NaiveDateTime values.

Should I go ahead and make a PR to add an implementation to vex/lib/vex/blank.ex?

iex(4)> act
%PlonquoApi.Models.Activity{__meta__: #Ecto.Schema.Metadata<:loaded, "activities">,
 id: 2, inserted_at: ~N[2017-12-22 14:38:55.445660],
 realised_end: ~N[2010-10-10 10:10:00.000000],
 realised_start: ~N[2010-10-10 10:00:00.000000],
 updated_at: ~N[2017-12-22 14:42:40.698299]}

iex(5)> Actionator.States.Activity.ActivityRealised.new(act)
%Actionator.States.Activity.ActivityRealised{realised_end: ~N[2010-10-10 10:10:00.000000],
 realised_start: ~N[2010-10-10 10:00:00.000000]}

iex(6)> Vex.valid? Actionator.States.Activity.ActivityRealised.new(act)
defmodule Actionator.States.Activity.ActivityRealised do
  defstruct realised_start: nil, realised_end: nil
  use Vex.Struct
  use ExConstructor

  validates :realised_start, [
    presence: true,
    by: &Actionator.Validations.Datetime.realised_start_before_realised_end/2
  ]
  validates :realised_end, presence: true

end
** (Protocol.UndefinedError) protocol Vex.Blank not implemented for ~N[2010-10-10 10:10:00.000000]. This protocol is implemented for: Actionator.States.Activity.ActivityPlanned, Actionator.States.Activity.ActivityRealised, Actionator.States.Activity.Any, Atom, BitString, Float, Integer, List, Map, Tuple
    (vex) deps/vex/lib/vex/blank.ex:1: Vex.Blank.impl_for!/1
    (vex) deps/vex/lib/vex/blank.ex:4: Vex.Blank.blank?/1
    (vex) lib/vex/validators/presence.ex:49: Vex.Validators.Presence.validate/2
    (vex) lib/vex.ex:48: Vex.result/4
    (elixir) lib/enum.ex:1273: Enum."-map/2-lists^map/1-0-"/2
    (elixir) lib/enum.ex:1277: anonymous fn/3 in Enum.map/2
    (stdlib) lists.erl:1263: :lists.foldl/3
    (elixir) lib/enum.ex:1846: Enum.map/2
    (vex) lib/vex.ex:31: Vex.results/2
    (vex) lib/vex.ex:24: Vex.errors/2
    (vex) lib/vex.ex:7: Vex.valid?/2