Skip to content

Instantly share code, notes, and snippets.

@rlgreen91
Created November 1, 2016 02:25
Show Gist options
  • Save rlgreen91/082e8fe8b145e37be595c1500cccec26 to your computer and use it in GitHub Desktop.
Save rlgreen91/082e8fe8b145e37be595c1500cccec26 to your computer and use it in GitHub Desktop.
Fun with Factories!
FactoryGirl.define do
factory :micropost do
content Faker::Lorem.characters(140)
user
end
factory :relationship do
follower_id
followed_id
end
factory :user do
name Faker::Name.name
sequence(:email) { |n| "example-#{n}@example.com"}
password 'password'
password_confirmation 'password'
activated true
activated_at Time.zone.now
factory :user_with_posts do
transient do
posts_count 1
end
after(:create) do |user,evaluator|
create_list(:micropost, evaluator.posts_count, user: user)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment