Commit 259f6f93 by Rocky Duan

use level instead of depth

parent 485b11b1
...@@ -26,14 +26,14 @@ namespace :db do ...@@ -26,14 +26,14 @@ namespace :db do
CommentThread.delete_all CommentThread.delete_all
Vote.delete_all Vote.delete_all
User.delete_all User.delete_all
depth_limit = YAML.load_file("config/application.yml")["depth_limit"] level_limit = YAML.load_file("config/application.yml")["level_limit"]
(1..3).each do |question_id| (1..3).each do |question_id|
comment_thread = CommentThread.create! :commentable_type => "questions", :commentable_id => question_id comment_thread = CommentThread.create! :commentable_type => "questions", :commentable_id => question_id
5.times do 5.times do
comment_thread.root_comments.create :body => "top comment", :title => "top #{rand(10)}", :user_id => 1, :course_id => 1, :comment_thread_id => comment_thread.id comment_thread.root_comments.create :body => "top comment", :title => "top #{rand(10)}", :user_id => 1, :course_id => 1, :comment_thread_id => comment_thread.id
end end
10.times do 10.times do
comment = Comment.all.reject{|c| c.is_root? or c.depth - 1 >= depth_limit or c.comment_thread_id != comment_thread.id}.sample comment = Comment.all.reject{|c| c.is_root? or c.depth >= level_limit or c.comment_thread_id != comment_thread.id}.sample
comment.children.create :body => "comment body", :title => "comment title #{rand(50)}", :user_id => 1, :course_id => 1, :comment_thread_id => comment_thread.id comment.children.create :body => "comment body", :title => "comment title #{rand(50)}", :user_id => 1, :course_id => 1, :comment_thread_id => comment_thread.id
end end
end end
......
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