Skip to content

Commit

Permalink
validate_required_attributes was not handling well false values
Browse files Browse the repository at this point in the history
  • Loading branch information
cblavier committed Jun 15, 2022
1 parent 4d94a86 commit 6884f14
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.3

- another fix on `validate_required_attributes` not handling well `false` values

# 1.0.2

- @seb3s fixed a bug, that make `validate_required_attributes` not raising with some
Expand Down
2 changes: 1 addition & 1 deletion lib/phx_component_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ defmodule PhxComponentHelpers do
def validate_required_attributes(assigns, nil), do: assigns

def validate_required_attributes(assigns, required) do
missing = for attr <- required, !Map.get(assigns, attr), do: attr
missing = for attr <- required, is_nil(Map.get(assigns, attr)), do: attr

if Enum.any?(missing) do
raise ArgumentError, "missing required attributes #{inspect(missing)}"
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule PhxComponentHelpers.MixProject do
def project do
[
app: :phx_component_helpers,
version: "1.0.2",
version: "1.0.3",
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down
6 changes: 6 additions & 0 deletions test/phx_component_helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ defmodule PhxComponentHelpersTest do
end
end

test "with required attributes filled with false, it shoud not raise" do
assigns = assigns(%{foo: "foo", bar: "bar"})

Helpers.set_attributes(assigns, [baz: false], required: [:baz])
end

test "with into option, it merges all in a single assign" do
assigns = assigns(%{foo: "foo", bar: "bar"})

Expand Down

0 comments on commit 6884f14

Please sign in to comment.