Skip to content

Instantly share code, notes, and snippets.

@momolog
Created March 9, 2018 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save momolog/d0725d3aa232c65a9328f832b88819e1 to your computer and use it in GitHub Desktop.
Save momolog/d0725d3aa232c65a9328f832b88819e1 to your computer and use it in GitHub Desktop.
Runs just fine with "ruby test.rb" under ruby 2.5
require 'factory_bot'
class Training
attr_accessor :instructor
def save!; end
end
class User
attr_accessor :role
def save!; end
end
class Activity
attr_accessor :name
def save!; end
end
class Role
attr_accessor :activities
def save!; end
end
FactoryBot.define do
factory :training do
transient do
assigned_instructor { create(:user) }
end
instructor { assigned_instructor }
end
factory :user do
role { create(:role, activities: [create(:activity, name: 'activity')]) }
end
factory :activity do
end
factory :role do
end
end
training = FactoryBot.create :training
p training.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment