Commit 5a61b818 by Rocky Duan

fix rake file

parent 563c7e10
...@@ -25,16 +25,13 @@ namespace :test do ...@@ -25,16 +25,13 @@ namespace :test do
50.times do 50.times do
Comment.delete_all Comment.delete_all
CommentThread.delete_all CommentThread.delete_all
Commentable.delete_all
User.delete_all User.delete_all
Notification.delete_all Notification.delete_all
Subscription.delete_all Subscription.delete_all
commentable = Commentable.create!(commentable_type: "questions", commentable_id: "1")
user = User.create!(external_id: "1") user = User.create!(external_id: "1")
comment_thread = commentable.comment_threads.new(title: "I can't solve this problem", body: "can anyone help me?", course_id: "1") comment_thread = CommentThread.new(title: "I can't solve this problem", body: "can anyone help me?", course_id: "1", commentable_id: "question_1")
comment_thread.author = user comment_thread.author = user
comment_thread.save! comment_thread.save!
...@@ -67,16 +64,22 @@ namespace :db do ...@@ -67,16 +64,22 @@ namespace :db do
Comment.create_indexes Comment.create_indexes
CommentThread.create_indexes CommentThread.create_indexes
User.create_indexes User.create_indexes
Commentable.create_indexes
Notification.create_indexes Notification.create_indexes
Subscription.create_indexes Subscription.create_indexes
Delayed::Backend::Mongoid::Job.create_indexes Delayed::Backend::Mongoid::Job.create_indexes
puts "finished" puts "finished"
end end
task :clean => :environment do
Comment.delete_all
CommentThread.delete_all
User.delete_all
Notification.delete_all
Subscription.delete_all
end
task :seed => :environment do task :seed => :environment do
Commentable.delete_all
Comment.delete_all Comment.delete_all
CommentThread.delete_all CommentThread.delete_all
User.delete_all User.delete_all
...@@ -93,13 +96,9 @@ namespace :db do ...@@ -93,13 +96,9 @@ namespace :db do
users.sample.subscribe(users.sample) users.sample.subscribe(users.sample)
end end
def generate_comments(commentable_type, commentable_id, level_limit, users) def generate_comments(commentable_id, level_limit, users)
commentable = Commentable.create!(commentable_type: commentable_type, commentable_id: commentable_id)
5.times do 5.times do
comment_thread = commentable.comment_threads.new( comment_thread = CommentThread.new(commentable_id: commentable_id, body: "This is a post", title: "Post No.#{rand(10)}", course_id: "1")
commentable_type: commentable_type, commentable_id: commentable_id,
body: "This is a post", title: "Post No.#{rand(10)}",
course_id: "1")
comment_thread.author = users.sample comment_thread.author = users.sample
comment_thread.save! comment_thread.save!
3.times do 3.times do
...@@ -115,15 +114,15 @@ namespace :db do ...@@ -115,15 +114,15 @@ namespace :db do
sub_comment.endorsed = [true, false].sample sub_comment.endorsed = [true, false].sample
sub_comment.save! sub_comment.save!
end end
puts "Generating a comment thread for #{commentable_type} No.#{commentable_id}" puts "Generating a comment thread for #{commentable_id}"
end end
end end
generate_comments("questions" , 1, level_limit, users) generate_comments("question_1", level_limit, users)
generate_comments("questions" , 2, level_limit, users) generate_comments("question_2", level_limit, users)
generate_comments("courses" , 1, level_limit, users) generate_comments("course_1", level_limit, users)
generate_comments("lectures" , 1, level_limit, users) generate_comments("lecture_1", level_limit, users)
generate_comments("lectures" , 2, level_limit, users) generate_comments("lecture_2", level_limit, users)
puts "voting" puts "voting"
users = [] users = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment