make a fake data for personal conference plugin

This commit is contained in:
Rueshyna 2013-02-07 18:33:06 +08:00 committed by chris
parent 1c4b696052
commit 2afbae7c08
9 changed files with 99 additions and 62 deletions

View File

@ -6,43 +6,53 @@ FactoryGirl.definition_file_paths = Dir["#{Rails.root}/vendor/built_in_modules/*
FactoryGirl.find_definitions
CoAuthorRelation.destroy_all
CoAuthor.destroy_all
JournalLevelType.destroy_all
WritingJournalFile.destroy_all
WritingJournal.destroy_all
ConferenceCoAuthorRelation.destroy_all
ConferenceCoAuthor.destroy_all
ConferencePaperType.destroy_all
WritingConferenceFile.destroy_all
WritingConference.destroy_all
#Dir[Rails.root.join("spec/factories/*.rb")].each {|f| require f}
10.size.times do
FactoryGirl.create(:journal_level)
2.times do
FactoryGirl.create(:conference_paper_type)
end
10.times do
FactoryGirl.create(:journal_relation)
end
50.times do
FactoryGirl.create(:journal)
end
50.times do
FactoryGirl.create(:journal_co_author)
end
10.size.times do
FactoryGirl.create(:conference_level)
end
10.times do
FactoryGirl.create(:conference_relation)
end
50.times do
FactoryGirl.create(:conference)
FactoryGirl.create(:conference_co_author_relation)
end
50.times do
FactoryGirl.create(:conference_co_author)
end
50.times do
FactoryGirl.create(:writing_conference)
end
puts "Success!"
# =======
#
#CoAuthorRelation.destroy_all
#CoAuthor.destroy_all
#JournalLevelType.destroy_all
#WritingJournalFile.destroy_all
#WritingJournal.destroy_all
#
#10.size.times do
# FactoryGirl.create(:journal_level)
#end
#
#10.times do
# FactoryGirl.create(:journal_relation)
#end
#
#50.times do
# FactoryGirl.create(:journal)
#end
#
#50.times do
# FactoryGirl.create(:journal_co_author)
#end
#puts "Success!"

View File

@ -0,0 +1,20 @@
class ConferenceCoAuthor
include Mongoid::Document
LANGUAGE_TYPES = [ "English", "Chinese" ]
field :name_id, type: BSON::ObjectId
field :co_author, localize: true
field :email
belongs_to :conference_co_author_relations
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/
validates :email, format: { with: VALID_EMAIL_REGEX },
allow_blank: true,
uniqueness: { case_sensitive: false }
validates :co_author, presence: true
before_save { |coauthor| coauthor.email = email.downcase if not coauthor.email.nil?}
end

View File

@ -0,0 +1,11 @@
class ConferenceCoAuthorRelation
include Mongoid::Document
include Mongoid::Timestamps
field :relation, localize: true
has_and_belongs_to_many :conference_co_authors
validates :relation, presence: true,
uniqueness: { case_sensitive: false }
end

View File

@ -2,7 +2,7 @@
types = ["friend", "teacher", "student", "schoolmate", "parent", "best friend", "instructor", "labmate", "TA", "mate"]
FactoryGirl.define do
factory(:relations, class: "CoAuthorRelation") do |f|
factory(:conference_co_author_relation, class: "ConferenceCoAuthorRelation") do |f|
f.sequence(:relation_translations) do |n|
{ zh_tw: "#{types[n%types.size]}",
en: "#{types[n%types.size]}" }

View File

@ -8,13 +8,13 @@ email = Array.new 51,""
email= email.map do |p| Faker::Internet.email end
FactoryGirl.define do
factory(:co_author_candidate, class: "CoAuthor") do |f|
factory(:conference_co_author, class: "ConferenceCoAuthor") 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(:conference_co_author_relations_id) do |n| "#{ConferenceCoAuthorRelation.all[n%ConferenceCoAuthorRelation.count].id}" end
f.sequence(:email) do |n| "#{email[n]}" end
f.name_id BSON::ObjectId('4f45f3b9e9d02c5db9000067') #user_id, this is Chris' account
end

View File

@ -0,0 +1,10 @@
level = ["Oral","Poster"]
FactoryGirl.define do
factory(:conference_paper_type, class: "ConferencePaperType") do |f|
f.sequence(:title_translations) do |n|
{ zh_tw: "#{level[n-1]}",
en: "#{level[n-1]}" }
end
end
end

View File

@ -1,10 +0,0 @@
level = ["SCI", "SCIE", "SSCI", "AH & HCI", "EI", "CSCI", "CSSCI", "TSCI", "TSSCI", "THCI"]
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
end

View File

@ -7,7 +7,7 @@ file = ["1.png", "5.pdf", "2.png", "6.pdf", "3.png", "7.pdf", "4.png"]
rand = Random.new
FactoryGirl.define do
factory(:upload_file, class: "WritingJournalFile") do |f|
factory(:writing_conference_file, class: "WritingConferenceFile") do |f|
f.sequence(:file) do |n|
File.new(File.join(Rails.root, "db" ,"files", file[rand.rand(0..6)]))
end

View File

@ -7,13 +7,13 @@ data_json = JSON.parse(data)
rand = Random.new
FactoryGirl.define do
factory :paper_record, class: "WritingJournal" do |f|
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(:journal_title_translations) do |n|
f.sequence(:conference_title_translations) do |n|
{zh_tw: "#{data_json[n]["booktitle"]}_tw",
en: "#{data_json[n]["booktitle"]}_en"}
end
@ -22,10 +22,6 @@ FactoryGirl.define do
"#{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
@ -34,17 +30,17 @@ FactoryGirl.define do
"#{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_start) do |n|
#"#{data_json[n]["page_from"]}"
#end
f.sequence(:form_to_end) do |n|
"#{data_json[n]["page_to"]}"
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(:total_pages) do |n|
#"#{data_json[n]["total_page"]}"
#end
f.sequence(:language) do |n|
"#{data_json[n]["language"]}"
@ -54,19 +50,19 @@ FactoryGirl.define do
"#{data_json[n]["abstract"].split[-3..-1].join(",")}"
end
f.sequence(:journal_level_types) do |n|
f.sequence(:conference_paper_types) do |n|
level = []
total_levels = rand.rand(1..JournalLevelType.count)
total_levels = rand.rand(0..ConferencePaperType.count-1)
total_levels.times do
level << JournalLevelType.all[rand.rand(0..JournalLevelType.count-1)]
level << ConferencePaperType.all[rand.rand(0..ConferencePaperType.count-1)]
end
level.uniq
end
f.sequence(:writing_journal_files) do |n|
f.sequence(:writing_conference_files) do |n|
files = []
total_files = rand.rand(1..7)
total_files.times do files << FactoryGirl.create(:upload_file) end
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