Skip to content

Instantly share code, notes, and snippets.

@mitsuru
Created June 24, 2021 09:36
Show Gist options
  • Save mitsuru/0c93d7dbd2b3ab578061c3bbf1258b0d to your computer and use it in GitHub Desktop.
Save mitsuru/0c93d7dbd2b3ab578061c3bbf1258b0d to your computer and use it in GitHub Desktop.
FactoryBot.define do
# @example Build :user as
# class Foo::User < ActiveType::Record[User]; end
#
# FactoryBot.build(:user, :typed, as: Foo::User)
trait :typed do
transient do
as { nil }
end
initialize_with do
if as
as.new(**attributes)
else
new(**attributes)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment