Skip to content

Commit

Permalink
FIX:Handle boolean fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmicahcooper committed Dec 2, 2020
1 parent a257e3a commit b72ecfd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ecto_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ defmodule EctoFactory do
{schema, attrs}
end

defp gen_attribute({key, value}) when is_atom(value), do: {key, gen(value)}
defp gen_attribute({key, value}) when is_atom(value) and value not in [true, false], do: {key, gen(value)}
defp gen_attribute({key, {_, _} = value}), do: {key, gen(value)}
defp gen_attribute(key_value), do: key_value

Expand Down
1 change: 1 addition & 0 deletions test/ecto_factory_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule EctoFactoryTest do
test "build by directly passing in a schema" do
user = EctoFactory.schema(User)
assert user
assert Enum.member?([true, false], user.admin)
end

test "build with attributes" do
Expand Down
1 change: 1 addition & 0 deletions test/support/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ defmodule User do
field(:date_of_birth, :date)
field(:addresses, {:array, :string})
field(:profile, :map)
field(:admin, :boolean)
end
end

0 comments on commit b72ecfd

Please sign in to comment.