make files and journal level fake data

This commit is contained in:
Rueshyna 2012-12-06 02:10:32 +08:00
parent 16e637260c
commit ddec333e03
8 changed files with 49 additions and 4 deletions

BIN
db/files/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 959 KiB

BIN
db/files/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1023 KiB

BIN
db/files/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 KiB

BIN
db/files/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1023 KiB

BIN
db/files/5.pdf Normal file

Binary file not shown.

BIN
db/files/6.pdf Normal file

Binary file not shown.

BIN
db/files/7.pdf Normal file

Binary file not shown.

View File

@ -5,6 +5,8 @@ require 'json'
CoAuthor.destroy_all CoAuthor.destroy_all
CoAuthorRelation.destroy_all CoAuthorRelation.destroy_all
WritingJournal.destroy_all WritingJournal.destroy_all
WritingJournalFile.destroy_all
JournalLevelType.destroy_all
data = File.read("db/data") data = File.read("db/data")
data_json = JSON.parse(data) data_json = JSON.parse(data)
@ -17,9 +19,32 @@ name_en = name_en.map do |p| Faker::Name::name end
email = Array.new 51,"" email = Array.new 51,""
email= email.map do |p| Faker::Internet.email end email= email.map do |p| Faker::Internet.email end
type = ["friend0", "teacher0", "student0", "mate0", "relation0", "friend1", "teacher1", "student1", "mate1", "relation1"] type = ["friend", "teacher", "student", "schoolmate", "parent", "best friend", "instructor", "labmate", "TA", "mate"]
file_desc = Array.new 7, ""
file_desc = file_desc.map do |p| Faker::Lorem.word end
file = ["1.png", "5.pdf", "2.png", "6.pdf", "3.png", "7.pdf", "4.png"]
level = ["SCI", "SCIE", "SSCI", "AH & HCI", "EI", "CSCI", "CSSCI", "TSCI", "TSSCI", "THCI"]
FactoryGirl.define do FactoryGirl.define do
factory(:journal_level, class: "JournalLevelType") do |f|
f.sequence(:title_translations) do |n|
{ zh_tw: "#{level[n]}",
en: "#{level[n]}" }
end
end
factory(:upload_file, class: "WritingJournalFile") do |f|
f.sequence(:file) do |n|
File.new(File.join(Rails.root, "db" ,"files", file[Random.rand(0..6)]))
end
f.sequence(:title) do |n|
"#{file_desc[Random.rand(0..6)]}"
end
end
factory(:type, class: "CoAuthorRelation") do |f| factory(:type, class: "CoAuthorRelation") do |f|
f.sequence(:relation_translations) do |n| f.sequence(:relation_translations) do |n|
{ zh_tw: "#{type[n%type.size]}", { zh_tw: "#{type[n%type.size]}",
@ -85,20 +110,40 @@ FactoryGirl.define do
"#{data_json[n]["abstract"].split[-3..-1].join(",")}" "#{data_json[n]["abstract"].split[-3..-1].join(",")}"
end end
f.sequence(:journal_level_types) do |n|
level = []
total_levels = Random.rand(1..JournalLevelType.count)
total_levels.times do
level << JournalLevelType.all[Random.rand(0..JournalLevelType.count-1)]
end
level.uniq
end
f.sequence(:writing_journal_files) do |n|
files = []
total_files = Random.rand(1..7)
total_files.times do files << FactoryGirl.create(:upload_file) end
files
end
f.create_user_id BSON::ObjectId('4f45f3b9e9d02c5db9000067') #user_id, this is Chris' account 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 f.update_user_id BSON::ObjectId('4f45f3b9e9d02c5db9000067') #user_id, this is Chris' account
end end
end end
10.times.each do (level.size - 1).times do
FactoryGirl.create(:journal_level)
end
10.times do
FactoryGirl.create(:type) FactoryGirl.create(:type)
end end
50.times.each do 50.times do
FactoryGirl.create(:paper_record) FactoryGirl.create(:paper_record)
end end
50.times.each do 50.times do
FactoryGirl.create(:co_author_candidate) FactoryGirl.create(:co_author_candidate)
end end
puts "Success!!!! Devin!"