fake data for journal and coauthor

This commit is contained in:
Rueshyna 2012-11-27 00:05:04 +08:00
parent c9e3d5271a
commit 6de62318c5
2 changed files with 533 additions and 508 deletions

918
db/data

File diff suppressed because it is too large Load Diff

View File

@ -1,62 +1,87 @@
require 'factory_girl' require 'factory_girl'
require 'faker'
require 'json' require 'json'
data = File.read("db/data") data = File.read("db/data")
data_json = JSON.parse(data) data_json = JSON.parse(data)
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
type = ["friend", "teacher", "student", "mate", "relation"]
FactoryGirl.define do FactoryGirl.define do
factory :paper_record, class: "WritingJournal" do |f| factory(:co_author_candidate, class: "CoAuthor") do |f|
f.sequence(:paper_title_translations) do |n|
{ zh_tw: "tw_#{data_json[n]["paper_title"]}",
en: "en_#{data_json[n]["paper_title"]}" }
end
f.sequence(:journal_title_translations) do |n| f.sequence(:co_author_translations) do |n|
{zh_tw: "tw_#{data_json[n]["booktitle"]}", { zh_tw: "#{name_tw[n]}",
en: "en_#{data_json[n]["booktitle"]}"} en: "#{name_en[n]}" }
end end
f.sequence(:type) do |n| "#{type[n%5]}" end
f.sequence(:email) do |n| "#{email[n]}" end
f.name_id BSON::ObjectId('4f45f3b9e9d02c5db9000067') #user_id, this is Chris' account
end
end
# factory :paper_record, class: "WritingJournal" do |f|
# f.sequence(:paper_title_translations) do |n|
# { zh_tw: "tw_#{data_json[n]["paper_title"]}",
# en: "en_#{data_json[n]["paper_title"]}" }
# end
#
# f.sequence(:journal_title_translations) do |n|
# {zh_tw: "tw_#{data_json[n]["booktitle"]}",
# en: "en_#{data_json[n]["booktitle"]}"}
# end
#
# f.sequence(:abstract) do |n|
# "#{data_json[n]["abstract"]}"
# end
#
# f.sequence(:isbn) do |n|
# "#{data_json[n]["isbn"]}"
# end
#
# f.sequence(:year) do |n|
# "#{data_json[n]["year"]}"
# end
#
# f.sequence(:authors) do |n|
# "#{data_json[n]["author"].map{|m| m.split(",").reverse.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.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
f.sequence(:abstract) do |n|
"#{data_json[n]["abstract"]}"
end
f.sequence(:isbn) do |n| #50.times.each do
"#{data_json[n]["isbn"]}" # FactoryGirl.create(:paper_record)
end #end
f.sequence(:year) do |n|
"#{data_json[n]["year"]}"
end
f.sequence(:authors) do |n|
"#{data_json[n]["author"].map{|m| m.split(",").reverse.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.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
50.times.each do 50.times.each do
FactoryGirl.create(:paper_record) FactoryGirl.create(:co_author_candidate)
end end