split db/seeds.rb file to local plugin and done journal

This commit is contained in:
Rueshyna 2013-02-26 15:52:20 +08:00
parent c55f64f3c6
commit 81725ed942
5 changed files with 28 additions and 55 deletions

View File

@ -5,54 +5,4 @@ FactoryGirl.definition_file_paths = Dir["#{Rails.root}/vendor/built_in_modules/*
FactoryGirl.find_definitions FactoryGirl.find_definitions
Dir["#{Rails.root}/vendor/built_in_modules/*/db/seeds.rb"].each { |seed| load seed }
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}
2.times do
FactoryGirl.create(:conference_paper_type)
end
10.times do
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,23 @@
JournalCoAuthorRelation.destroy_all
JournalCoAuthor.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_co_author_relation)
end
50.times do
FactoryGirl.create(:writing_journal)
end
50.times do
FactoryGirl.create(:journal_co_author)
end
puts "Journal sample data import success!"

View File

@ -2,7 +2,7 @@
types = ["friend", "teacher", "student", "schoolmate", "parent", "best friend", "instructor", "labmate", "TA", "mate"] types = ["friend", "teacher", "student", "schoolmate", "parent", "best friend", "instructor", "labmate", "TA", "mate"]
FactoryGirl.define do FactoryGirl.define do
factory(:journal_co_author_relation, class: "CoAuthorRelation") do |f| factory(:journal_co_author_relation, class: "JournalCoAuthorRelation") do |f|
f.sequence(:relation_translations) do |n| f.sequence(:relation_translations) do |n|
{ zh_tw: "#{types[n%types.size]}", { zh_tw: "#{types[n%types.size]}",
en: "#{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 email= email.map do |p| Faker::Internet.email end
FactoryGirl.define do FactoryGirl.define do
factory(:journal_co_author, class: "CoAuthor") do |f| factory(:journal_co_author, class: "JournalCoAuthor") do |f|
f.sequence(:co_author_translations) do |n| f.sequence(:co_author_translations) do |n|
{ zh_tw: "#{name_tw[n]}", { zh_tw: "#{name_tw[n]}",
en: "#{name_en[n]}" } en: "#{name_en[n]}" }
end end
f.sequence(:co_author_relations_id) do |n| "#{CoAuthorRelation.all[n%CoAuthorRelation.count].id}" end f.sequence(:journal_co_author_relations_id) do |n| "#{JournalCoAuthorRelation.all[n%JournalCoAuthorRelation.count].id}" end
f.sequence(:email) do |n| "#{email[n]}" end f.sequence(:email) do |n| "#{email[n]}" end
f.name_id BSON::ObjectId('4f45f3b9e9d02c5db9000067') #user_id, this is Chris' account f.name_id BSON::ObjectId('4f45f3b9e9d02c5db9000067') #user_id, this is Chris' account
end end

View File

@ -7,7 +7,7 @@ data_json = JSON.parse(data)
rand = Random.new rand = Random.new
FactoryGirl.define do FactoryGirl.define do
factory :journal, class: "WritingJournal" do |f| factory :writing_journal, class: "WritingJournal" do |f|
f.sequence(:paper_title_translations) do |n| f.sequence(:paper_title_translations) do |n|
{ zh_tw: "#{data_json[n]["paper_title"]}_tw", { zh_tw: "#{data_json[n]["paper_title"]}_tw",
en: "#{data_json[n]["paper_title"]}_en" } en: "#{data_json[n]["paper_title"]}_en" }