Commit c1b96347 by Rocky Duan

updated taggable gem to use real time update

parent ae31222b
......@@ -26,7 +26,7 @@ gem 'delayed_job_mongoid', :git => 'git@github.com:dementrock/delayed_job_mongoi
gem 'mongoid-tree', :git => 'git@github.com:dementrock/mongoid-tree.git'
gem 'voteable_mongo', :git => 'git@github.com:dementrock/voteable_mongo.git'
gem 'mongoid_taggable', :git => 'git@github.com:dementrock/mongoid_taggable.git'
gem 'mongoid_taggable_with_context', :git => 'git@github.com:dementrock/mongoid_taggable_with_context.git'
gem 'mongoid_magic_counter_cache', :git => 'git@github.com:dementrock/mongoid-magic-counter-cache.git'
gem 'kaminari', :require => 'kaminari/sinatra', :git => 'git@github.com:dementrock/kaminari.git'
......
......@@ -30,47 +30,6 @@ def create_test_user(id)
User.create!(external_id: id, username: "user#{id}", email: "user#{id}@test.com")
end
namespace :test do
task :nested_comments => :environment do
puts "checking"
50.times do
Comment.delete_all
CommentThread.delete_all
User.delete_all
Notification.delete_all
Subscription.delete_all
user = create_test_user(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.save!
comment = comment_thread.comments.new(body: "this problem is so easy", course_id: "1")
comment.author = user
comment.save!
comment1 = comment.children.new(body: "not for me!", course_id: "1")
comment1.author = user
comment1.comment_thread = comment_thread
comment1.save!
comment2 = comment1.children.new(body: "not for me neither!", course_id: "1")
comment2.author = user
comment2.comment_thread = comment_thread
comment2.save!
children = comment_thread.root_comments.first.to_hash(recursive: true)["children"]
if children.length == 2
pp comment_thread.to_hash(recursive: true)
pp comment_thread.root_comments.first.descendants_and_self.to_a
puts "error!"
break
end
puts "passed once"
end
puts "passed"
end
end
task :console => :environment do
binding.pry
end
......@@ -90,6 +49,7 @@ namespace :db do
task :clean => :environment do
Comment.delete_all
CommentThread.delete_all
CommentThread.recalculate_all_context_tag_weights!
User.delete_all
Notification.delete_all
Subscription.delete_all
......@@ -196,6 +156,7 @@ namespace :db do
Comment.delete_all
CommentThread.delete_all
CommentThread.recalculate_all_context_tag_weights!
User.delete_all
Notification.delete_all
Subscription.delete_all
......
......@@ -3,5 +3,5 @@ get "#{APIPREFIX}/threads/tags" do
end
get "#{APIPREFIX}/threads/tags/autocomplete" do
CommentThread.tags_autocomplete(params["value"].strip, max: 5, sort_by_count: true).map(&:first).to_json
CommentThread.tags_autocomplete(:tags, params["value"].strip, max: 5, sort_by_count: true).map(&:first).to_json
end
......@@ -3,9 +3,11 @@ require_relative 'content'
class CommentThread < Content
include Mongo::Voteable
include Mongoid::Timestamps
include Mongoid::Taggable
include Mongoid::TaggableWithContext
include Mongoid::TaggableWithContext::AggregationStrategy::RealTime
voteable self, :up => +1, :down => -1
taggable separator: ',', default: []
field :comment_count, type: Integer, default: 0
field :title, type: String
......@@ -115,7 +117,6 @@ class CommentThread < Content
def activity_overall; activity_since(nil); end
def root_comments
Comment.roots.where(comment_thread_id: self.id)
end
......
......@@ -137,6 +137,7 @@ describe "app" do
end
describe "GET /api/v1/threads/tags" do
it "get all tags used in threads" do
CommentThread.recalculate_all_context_tag_weights!
thread1 = CommentThread.all.to_a.first
thread2 = CommentThread.all.to_a.last
thread1.tags = "a, b, c"
......@@ -161,6 +162,7 @@ describe "app" do
end
it "returns autocomplete results" do
CommentThread.delete_all
CommentThread.recalculate_all_context_tag_weights!
create_comment_thread "c++, clojure, common-lisp, c#, c, coffeescript"
create_comment_thread "c++, clojure, common-lisp, c#, c"
create_comment_thread "c++, clojure, common-lisp, c#"
......
......@@ -37,6 +37,7 @@ end
def init_without_subscriptions
Comment.delete_all
CommentThread.delete_all
CommentThread.recalculate_all_context_tag_weights!
User.delete_all
Notification.delete_all
Subscription.delete_all
......@@ -109,6 +110,7 @@ end
def init_with_subscriptions
Comment.delete_all
CommentThread.delete_all
CommentThread.recalculate_all_context_tag_weights!
User.delete_all
Notification.delete_all
Subscription.delete_all
......
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