Repository: keathley/norm (elixir)

Issue:
Specifying that a value in a map or struct can be nil
It doesn't seem to be possible to specify that a value in map or struct can also be `nil`:

```elixir
conform(%{foo: nil}, schema(%{foo: spec(is_binary() or is_nil())}))
# => {:error, ["val: %{foo: nil} in: :foo fails: :required"]}
```

Am I missing something or is this a bug? 


Pull request description:
Allow schema's to specify a value is nil.
Closes #17 

Patch:
diff --git a/lib/norm/schema.ex b/lib/norm/schema.ex
index 98386eb..b7b2e44 100644
--- a/lib/norm/schema.ex
+++ b/lib/norm/schema.ex
@@ -90,12 +90,13 @@ defmodule Norm.Schema do
     end
 
     defp check_spec({key, spec}, input, path) do
-      val = Map.get(input, key)
+      case Map.has_key?(input, key) do
+        false ->
+          {key, {:error, [error(path ++ [key], input, ":required")]}}
 
-      if val == nil do
-        {key, {:error, [error(path ++ [key], input, ":required")]}}
-      else
-        {key, Conformable.conform(spec, val, path ++ [key])}
+        true ->
+          val = Map.get(input, key)
+          {key, Conformable.conform(spec, val, path ++ [key])}
       end
     end
 


Test patch:
diff --git a/test/norm/schema_test.exs b/test/norm/schema_test.exs
index bc0df4a..ee4163a 100644
--- a/test/norm/schema_test.exs
+++ b/test/norm/schema_test.exs
@@ -58,6 +58,14 @@ defmodule Norm.SchemaTest do
     assert %{bool: false} == conform!(%{bool: false}, s)
   end
 
+  test "allows keys to have nil values" do
+    s = schema(%{foo: spec(is_nil())})
+
+    assert %{foo: nil} == conform!(%{foo: nil}, s)
+    assert {:error, errors} = conform(%{foo: 123}, s)
+    assert errors == ["val: 123 in: :foo fails: is_nil()"]
+  end
+
   describe "generation" do
     test "works with maps" do
       s =