Commit c5d51bba by Matthew Mongeau

Add endoresed information for threads.

parent 95c6f3d3
......@@ -145,6 +145,10 @@ class CommentThread < Content
subscriptions.map(&:subscriber)
end
def endorsed?
comments.where(endorsed: true).exists?
end
def to_hash(params={})
doc = as_document.slice(*%w[title body course_id anonymous commentable_id created_at updated_at at_position_list closed])
.merge("id" => _id)
......@@ -153,6 +157,7 @@ class CommentThread < Content
.merge("votes" => votes.slice(*%w[count up_count down_count point]))
.merge("tags" => tags_array)
.merge("type" => "thread")
.merge("endorsed" => endorsed?)
if params[:recursive]
doc = doc.merge("children" => root_comments.map{|c| c.to_hash(recursive: true)})
......
......@@ -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
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
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