orbit-personalconference/spec/factories/writing_conferences.rb

72 lines
1.9 KiB
Ruby
Raw Normal View History

2014-01-15 10:49:46 +00:00
require 'json'
data = File.read("#{Rails.root}/db/data")
data_json = JSON.parse(data)
rand = Random.new
FactoryGirl.define do
factory :writing_conference, class: "WritingConference" do |f|
f.sequence(:paper_title_translations) do |n|
{ zh_tw: "#{data_json[n]["paper_title"]}_tw",
en: "#{data_json[n]["paper_title"]}_en" }
end
f.sequence(:conference_title_translations) do |n|
{zh_tw: "#{data_json[n]["booktitle"]}_tw",
en: "#{data_json[n]["booktitle"]}_en"}
end
f.sequence(:abstract) do |n|
"#{data_json[n]["abstract"]}"
end
f.sequence(:year) do |n|
"#{data_json[n]["year"]}"
end
f.sequence(:author_tokens) do |n|
"#{data_json[n]["author"].map{|m| m.split(",").reverse.map(&:strip).join(" ")}.join(",")}"
end
#f.sequence(:form_to_start) do |n|
#"#{data_json[n]["page_from"]}"
#end
#f.sequence(:form_to_end) do |n|
#"#{data_json[n]["page_to"]}"
#end
#f.sequence(:total_pages) do |n|
#"#{data_json[n]["total_page"]}"
#end
f.sequence(:language) do |n|
"#{data_json[n]["language"]}"
end
f.sequence(:keywords) do |n|
"#{data_json[n]["abstract"].split[-3..-1].join(",")}"
end
f.sequence(:conference_paper_types) do |n|
level = []
total_levels = rand.rand(0..ConferencePaperType.count-1)
total_levels.times do
level << ConferencePaperType.all[rand.rand(0..ConferencePaperType.count-1)]
end
level.uniq
end
f.sequence(:writing_conference_files) do |n|
files = []
total_files = rand.rand(1..7)
total_files.times do files << FactoryGirl.create(:writing_conference_file) end
files
end
f.create_user_id BSON::ObjectId('4f45f3b9e9d02c5db9000067') #user_id, this is Chris' account
f.update_user_id BSON::ObjectId('4f45f3b9e9d02c5db9000067') #user_id, this is Chris' account
end
end