Skip to content

Commit

Permalink
Merge pull request #117 from edx/gprice/commentable-course-id-filter
Browse files Browse the repository at this point in the history
Filter commentable queries by course_id
  • Loading branch information
Greg Price committed Sep 8, 2014
2 parents d26bc6b + d2e1413 commit 2d2a05a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/commentables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions spec/api/commentable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d2a05a

Please sign in to comment.