From 2afbae7c087e2e26a1ec8a2f17a2a8d7e6884d45 Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Thu, 7 Feb 2013 18:33:06 +0800 Subject: [PATCH] make a fake data for personal conference plugin --- db/seeds.rb | 66 +++++++++++-------- .../app/models/conference_co_author.rb | 20 ++++++ .../models/conference_co_author_relation.rb | 11 ++++ ...s.rb => conference_co_author_relations.rb} | 2 +- ...co_authors.rb => conference_co_authors.rb} | 4 +- .../spec/factories/conference_paper_type.rb | 10 +++ .../spec/factories/journal_level_types.rb | 10 --- .../factories/writing_conference_files.rb | 2 +- .../spec/factories/writing_conferences.rb | 36 +++++----- 9 files changed, 99 insertions(+), 62 deletions(-) create mode 100644 vendor/built_in_modules/personal_conference/app/models/conference_co_author.rb create mode 100644 vendor/built_in_modules/personal_conference/app/models/conference_co_author_relation.rb rename vendor/built_in_modules/personal_conference/spec/factories/{co_author_relations.rb => conference_co_author_relations.rb} (77%) rename vendor/built_in_modules/personal_conference/spec/factories/{co_authors.rb => conference_co_authors.rb} (71%) create mode 100644 vendor/built_in_modules/personal_conference/spec/factories/conference_paper_type.rb delete mode 100644 vendor/built_in_modules/personal_conference/spec/factories/journal_level_types.rb diff --git a/db/seeds.rb b/db/seeds.rb index 91469233..a0458dd1 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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!" diff --git a/vendor/built_in_modules/personal_conference/app/models/conference_co_author.rb b/vendor/built_in_modules/personal_conference/app/models/conference_co_author.rb new file mode 100644 index 00000000..71e5b17f --- /dev/null +++ b/vendor/built_in_modules/personal_conference/app/models/conference_co_author.rb @@ -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 + diff --git a/vendor/built_in_modules/personal_conference/app/models/conference_co_author_relation.rb b/vendor/built_in_modules/personal_conference/app/models/conference_co_author_relation.rb new file mode 100644 index 00000000..f36e5132 --- /dev/null +++ b/vendor/built_in_modules/personal_conference/app/models/conference_co_author_relation.rb @@ -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 diff --git a/vendor/built_in_modules/personal_conference/spec/factories/co_author_relations.rb b/vendor/built_in_modules/personal_conference/spec/factories/conference_co_author_relations.rb similarity index 77% rename from vendor/built_in_modules/personal_conference/spec/factories/co_author_relations.rb rename to vendor/built_in_modules/personal_conference/spec/factories/conference_co_author_relations.rb index 09fc6d88..4e4de257 100644 --- a/vendor/built_in_modules/personal_conference/spec/factories/co_author_relations.rb +++ b/vendor/built_in_modules/personal_conference/spec/factories/conference_co_author_relations.rb @@ -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]}" } diff --git a/vendor/built_in_modules/personal_conference/spec/factories/co_authors.rb b/vendor/built_in_modules/personal_conference/spec/factories/conference_co_authors.rb similarity index 71% rename from vendor/built_in_modules/personal_conference/spec/factories/co_authors.rb rename to vendor/built_in_modules/personal_conference/spec/factories/conference_co_authors.rb index 75a11c9b..cc9954bf 100644 --- a/vendor/built_in_modules/personal_conference/spec/factories/co_authors.rb +++ b/vendor/built_in_modules/personal_conference/spec/factories/conference_co_authors.rb @@ -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 diff --git a/vendor/built_in_modules/personal_conference/spec/factories/conference_paper_type.rb b/vendor/built_in_modules/personal_conference/spec/factories/conference_paper_type.rb new file mode 100644 index 00000000..130b8a9b --- /dev/null +++ b/vendor/built_in_modules/personal_conference/spec/factories/conference_paper_type.rb @@ -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 diff --git a/vendor/built_in_modules/personal_conference/spec/factories/journal_level_types.rb b/vendor/built_in_modules/personal_conference/spec/factories/journal_level_types.rb deleted file mode 100644 index 631a39c9..00000000 --- a/vendor/built_in_modules/personal_conference/spec/factories/journal_level_types.rb +++ /dev/null @@ -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 diff --git a/vendor/built_in_modules/personal_conference/spec/factories/writing_conference_files.rb b/vendor/built_in_modules/personal_conference/spec/factories/writing_conference_files.rb index 67c47e3d..54dc9914 100644 --- a/vendor/built_in_modules/personal_conference/spec/factories/writing_conference_files.rb +++ b/vendor/built_in_modules/personal_conference/spec/factories/writing_conference_files.rb @@ -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 diff --git a/vendor/built_in_modules/personal_conference/spec/factories/writing_conferences.rb b/vendor/built_in_modules/personal_conference/spec/factories/writing_conferences.rb index 3c9b20ca..759e47d4 100644 --- a/vendor/built_in_modules/personal_conference/spec/factories/writing_conferences.rb +++ b/vendor/built_in_modules/personal_conference/spec/factories/writing_conferences.rb @@ -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