mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
fix: avoid exception in Changeset.new/2
for bad attribute
This commit is contained in:
parent
f1a6fb7418
commit
b98650aeb7
2 changed files with 10 additions and 5 deletions
|
@ -1576,11 +1576,6 @@ defmodule Ash.Changeset do
|
|||
name: attribute
|
||||
)
|
||||
|
||||
changeset = %{
|
||||
changeset
|
||||
| attributes: Map.put(changeset.attributes, attribute.name, value)
|
||||
}
|
||||
|
||||
add_error(changeset, error)
|
||||
|
||||
%{writable?: false} = attribute ->
|
||||
|
|
|
@ -433,6 +433,16 @@ defmodule Ash.Test.Changeset.ChangesetTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "if an attribute does not exist in `new/2`, a corresponding error is added`" do
|
||||
error =
|
||||
Author
|
||||
|> Changeset.new(%{"flarb" => 10})
|
||||
|> Map.get(:errors)
|
||||
|> Enum.at(0)
|
||||
|
||||
assert %Ash.Error.Changes.NoSuchAttribute{name: "flarb"} = error
|
||||
end
|
||||
|
||||
test "it destroys related records if not present" do
|
||||
post1 = %{title: "title"}
|
||||
post2 = %{title: "title"}
|
||||
|
|
Loading…
Reference in a new issue