bug: Add failing test for auto-build and relate options colliding

This commit is contained in:
Rebecca Le 2024-05-29 11:37:05 +08:00 committed by James Harton
parent ebc07800b4
commit d5be51556d

View file

@ -178,6 +178,30 @@ defmodule Smokestack.DslTest do
assert %Post{author: %Author{}} = AutoBuildFactory.insert!(Post)
end
test "auto builds can be overridden at runtime" do
defmodule AutoBuildRelateFactory do
@moduledoc false
use Smokestack
factory Post do
attribute :title, &Faker.Company.catch_phrase/0
auto_build :author
end
factory Author do
attribute :name, &Faker.Internet.email/0
attribute :email, &Faker.Person.name/0
end
end
author = AutoBuildRelateFactory.insert!(Author)
post = AutoBuildRelateFactory.insert!(Post, relate: [author: author])
# The auto-build should not be used - the existing author should be used
assert Ash.count(Author) == 1
assert post.author.id == author.id
end
test "auto loads can be specified in the factory" do
defmodule AutoLoadFactory do
@moduledoc false