Created
November 3, 2022 15:10
-
-
Save composerinteralia/1c95e8d2d4599d4859e3663c8f512391 to your computer and use it in GitHub Desktop.
This file contains 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
class SeedQueue | |
def self.<<(seed) | |
seed.plant | |
end | |
end | |
class Seed | |
include ActiveModel::Attributes | |
end | |
class UserSeed < Seed | |
attribute :name, :string | |
attribute :email, :string | |
attribute :plan, :string | |
def plant | |
p attributes | |
end | |
end | |
class IssueSeed < Seed | |
attribute :title, :string | |
attr_accessor :user_seed | |
def plant | |
p attributes.merge!(user: user_seed.attributes) | |
end | |
end | |
FactoryBot.define do | |
trait :seed do | |
to_create do |object| | |
SeedQueue << object | |
end | |
end | |
factory :user_seed do | |
seed | |
transient do | |
user_data { attributes_for(:user) } | |
org_data { attributes_for(:organization) } | |
end | |
email { user_data[:email] } | |
plan { org_data[:plan] } | |
name { "Default Name" } | |
end | |
factory :issue_seed do | |
seed | |
transient do | |
issue_data { attributes_for(:issue) } | |
end | |
title { issue_data[:title] } | |
association :user_seed | |
end | |
end | |
create(:user_seed, name: "my name", email: "myemail@example.com") | |
create_list(:user_seed, 5) | |
create(:issue_seed) | |
create(:user_seed) do |user_seed| | |
create(:issue_seed, user_seed: user_seed) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment