Merge branch 'fake_journal_data' into publication

* fake_journal_data:
  make a 'real' fake data
This commit is contained in:
Rueshyna 2012-11-26 14:05:50 +08:00
commit f2d1b0eaf7
3 changed files with 2480 additions and 23 deletions

View File

@ -2,7 +2,7 @@ defaults: &defaults
host: localhost host: localhost
# slaves: # slaves:
# - host: slave1.local # - host: slave1.local
port: 37017 port: 27017
# - host: slave2.local # - host: slave2.local
# port: 27019 # port: 27019

2429
db/data Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,62 @@
require 'factory_girl' require 'factory_girl'
require 'json'
data = File.read("db/data")
data_json = JSON.parse(data)
FactoryGirl.define do FactoryGirl.define do
factory :paper_record, class: "WritingJournal" do |f| factory :paper_record, class: "WritingJournal" do |f|
f.sequence(:paper_title_translations) {|n|{zh_tw: "tw_test #{n}", en: "en_test #{n}" }} f.sequence(:paper_title_translations) do |n|
f.sequence(:journal_title_translations) {|n| {zh_tw: "tw_test #{n}", en: "en_test #{n}"}} { zh_tw: "tw_#{data_json[n]["paper_title"]}",
f.sequence(:keywords) {|n| "keywords #{n}"} en: "en_#{data_json[n]["paper_title"]}" }
f.sequence(:abstract) {|n| "abstract #{n}"} end
f.sequence(:isbn) {|n| "0714312#{n}#{n}#{n}"}
f.sequence(:year) {|n| "201#{n}"} f.sequence(:journal_title_translations) do |n|
f.create_user_id BSON::ObjectId('4f45f3b9e9d02c5db9000067') #user_id, this is Chris' account {zh_tw: "tw_#{data_json[n]["booktitle"]}",
f.update_user_id BSON::ObjectId('4f45f3b9e9d02c5db9000067') #user_id, this is Chris' account 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 end
factory :custom_record, class: "WritingJournal" do |f|
f.sequence(:paper_title_translations) {|n|{zh_tw: "tw_test #{n}", en: "en_test #{n}" }}
f.sequence(:keywords) {|n| "keywords #{n}"}
f.sequence(:abstract) {|n| "abstract #{n}"}
f.sequence(:isbn) {|n| "0714312#{n}#{n}#{n}"}
f.sequence(:year) {|n| "201#{n}"}
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
#product 50 records
#
50.times.each do 50.times.each do
FactoryGirl.create(:paper_record) FactoryGirl.create(:paper_record)
end end
FactoryGirl.create(:custom_record, journal_title_translations: {zh_tw: "tw_test A", en: "en_test A"})
FactoryGirl.create(:custom_record, journal_title_translations: {zh_tw: "tw_test B", en: "en_test B"})