Commit 2af135dd by arjun810

Merge pull request #4 from rll/mm-endorsed

Add endoresed information for threads.
parents 95941b36 c5d51bba
...@@ -147,6 +147,10 @@ class CommentThread < Content ...@@ -147,6 +147,10 @@ class CommentThread < Content
subscriptions.map(&:subscriber) subscriptions.map(&:subscriber)
end end
def endorsed?
comments.where(endorsed: true).exists?
end
def to_hash(params={}) def to_hash(params={})
doc = as_document.slice(*%w[title body course_id anonymous commentable_id created_at updated_at at_position_list closed]) doc = as_document.slice(*%w[title body course_id anonymous commentable_id created_at updated_at at_position_list closed])
.merge("id" => _id) .merge("id" => _id)
...@@ -155,6 +159,7 @@ class CommentThread < Content ...@@ -155,6 +159,7 @@ class CommentThread < Content
.merge("votes" => votes.slice(*%w[count up_count down_count point])) .merge("votes" => votes.slice(*%w[count up_count down_count point]))
.merge("tags" => tags_array) .merge("tags" => tags_array)
.merge("type" => "thread") .merge("type" => "thread")
.merge("endorsed" => endorsed?)
if params[:recursive] if params[:recursive]
doc = doc.merge("children" => root_comments.map{|c| c.to_hash(recursive: true)}) doc = doc.merge("children" => root_comments.map{|c| c.to_hash(recursive: true)})
......
...@@ -20,4 +20,28 @@ describe CommentThread do ...@@ -20,4 +20,28 @@ describe CommentThread do
CommentThread.tag_name_valid?("_this-is-a-tag").should be_false CommentThread.tag_name_valid?("_this-is-a-tag").should be_false
CommentThread.tag_name_valid?("this-is+a-tag").should be_false CommentThread.tag_name_valid?("this-is+a-tag").should be_false
end end
context "endorsed?" do
it "knows if it is #endorsed?" do
thread = CommentThread.new
criteria = build_criteria(thread, :exists? => true)
thread.endorsed?.should be_true
end
it "knows when it is not #endorsed?" do
thread = CommentThread.new
criteria = build_criteria(thread, :exists? => false)
thread.endorsed?.should be_false
end
def build_criteria(thread, options)
double("criteria").tap do |criteria|
comments = double("relation")
comments.stub(:where).with(endorsed: true).and_return(criteria)
thread.stub(:comments).and_return(comments)
criteria.stub(options)
end
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