Skip to content

Instantly share code, notes, and snippets.

@jgv
Last active December 11, 2015 17:59
Show Gist options
  • Save jgv/4638576 to your computer and use it in GitHub Desktop.
Save jgv/4638576 to your computer and use it in GitHub Desktop.
Factory Girl definitions.
# Picture factory definition
FactoryGirl.define do
factory :picture do
image { File.open(Dir.glob(File.join(Rails.root) + "/spec/support/pictures/*").sample) }
end
end
# Product factory definition
FactoryGirl.define do
factory :product do
name "a thing"
price "420"
description "blah blah blah"
slug "a-thing"
before(:create) {|p|
pics = []
2.times { pics << FactoryGirl.create(:picture, :attachable => p) }
p.pics << pics
}
user
end
end
# User factory definition
FactoryGirl.define do
factory :user do
sequence(:email) {|n| "person-#{n}@okfoc.us" }
firstname "tester"
sequence(:lastname) {|n| "cool #{n}" }
password "password"
sequence(:username) {|n| "foo-#{n}" }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment