Created
June 24, 2021 09:36
-
-
Save mitsuru/0c93d7dbd2b3ab578061c3bbf1258b0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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