From d2e14133b133c0c1396515c29dc28c3a7ba46eb5 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Fri, 5 Sep 2014 13:08:30 -0400 Subject: [PATCH] Filter commentable queries by course_id Bug: TNL-207 --- api/commentables.rb | 3 +++ spec/api/commentable_spec.rb | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/api/commentables.rb b/api/commentables.rb index bde292c8293..64fccee1a79 100644 --- a/api/commentables.rb +++ b/api/commentables.rb @@ -5,6 +5,9 @@ get "#{APIPREFIX}/:commentable_id/threads" do |commentable_id| threads = Content.where({"_type" => "CommentThread", "commentable_id" => commentable_id}) + if params["course_id"] + threads = threads.where({"course_id" => params["course_id"]}) + end handle_threads_query( threads, diff --git a/spec/api/commentable_spec.rb b/spec/api/commentable_spec.rb index a439f5a7db4..e8393f0521e 100644 --- a/spec/api/commentable_spec.rb +++ b/spec/api/commentable_spec.rb @@ -32,6 +32,13 @@ def thread_result(commentable_id, params={}) threads.index{|c| c["body"] == "can anyone help me?"}.should_not be_nil threads.index{|c| c["body"] == "it is unsolvable"}.should_not be_nil end + it "filters by course_id" do + course1_threads = thread_result "question_1", course_id: "1" + course1_threads.length.should == 1 + course2_threads = thread_result "question_1", course_id: "2" + course2_threads.length.should == 1 + course1_threads.should_not == course2_threads + end it "filters by group_id" do group_thread = Commentable.find("question_1").comment_threads.first threads = thread_result "question_1", group_id: 42