CoAuthor.destroy_all name_tw = Array.new 51,"" name_tw = name_tw.map do |p| Faker::Name::name end name_en = Array.new 51,"" name_en = name_en.map do |p| Faker::Name::name end email = Array.new 51,"" email= email.map do |p| Faker::Internet.email end FactoryGirl.define do factory(:co_author_candidate, class: "CoAuthor") do |f| f.sequence(:co_author_translations) do |n| { zh_tw: "#{name_tw[n]}", en: "#{name_en[n]}" } end f.sequence(:co_author_relations_id) do |n| "#{CoAuthorRelation.all[n%CoAuthorRelation.count].id}" end f.sequence(:email) do |n| "#{email[n]}" end f.name_id BSON::ObjectId('4f45f3b9e9d02c5db9000067') #user_id, this is Chris' account end end