Skip to content

Commit

Permalink
MA-1930 add thread count in GET
Browse files Browse the repository at this point in the history
  • Loading branch information
wajeeha-khalid committed Jan 27, 2016
1 parent fa2a260 commit a191ed3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

2 changes: 1 addition & 1 deletion lib/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def handle_threads_query(
pres_threads = ThreadListPresenter.new(threads, request_user, course_id)
collection = pres_threads.to_hash
end
{collection: collection, num_pages: num_pages, page: page}
{collection: collection, num_pages: num_pages, page: page, thread_count: comment_threads.count}
end
end

Expand Down
24 changes: 21 additions & 3 deletions spec/api/comment_thread_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,29 +334,46 @@ def move_to_front(ary, *vals)
end

context "pagination" do
def thread_result_page (sort_key, sort_order, page, per_page, user_id=nil, unread=false)
get "/api/v1/threads", course_id: DFLT_COURSE_ID, sort_key: sort_key, sort_order: sort_order, page: page, per_page: per_page, user_id: user_id, unread: unread
def thread_result_page (sort_key, sort_order, page, per_page, course_id=DFLT_COURSE_ID, user_id=nil, unread=false)
get "/api/v1/threads", course_id: course_id, sort_key: sort_key, sort_order: sort_order, page: page, per_page: per_page, user_id: user_id, unread: unread
last_response.should be_ok
parse(last_response.body)
end

it "returns single page with no threads in a course" do
result = thread_result_page("date", "desc", 1, 20, "99")
result["collection"].length.should == 0
result["thread_count"].should == 0
result["num_pages"].should == 1
result["page"].should == 1
end
it "returns single page" do
result = thread_result_page("date", "desc", 1, 20)
result["collection"].length.should == 10
result["thread_count"].should == 10
result["num_pages"].should == 1
result["page"].should == 1
end
it "returns multiple pages" do
result = thread_result_page("date", "desc", 1, 5)
result["collection"].length.should == 5
result["thread_count"].should == 10
result["num_pages"].should == 2
result["page"].should == 1

result = thread_result_page("date", "desc", 2, 5)
result["collection"].length.should == 5
result["thread_count"].should == 10
result["num_pages"].should == 2
result["page"].should == 2
end
it "returns page exceeding available pages with no results" do
#TODO: Review whether we can switch pagination endpoint to raise an exception; rather than an empty page
result = thread_result_page("date", "desc", 3, 5)
result["collection"].length.should == 0
result["thread_count"].should == 10
result["num_pages"].should == 2
result["page"].should == 3
end

def test_paged_order (sort_spec, expected_order, filter_spec=[], user_id=nil)
# sort spec is a hash with keys: sort_key, sort_dir, per_page
Expand All @@ -372,6 +389,7 @@ def test_paged_order (sort_spec, expected_order, filter_spec=[], user_id=nil)
sort_spec['sort_dir'],
page,
per_page,
DFLT_COURSE_ID,
user_id,
filter_spec.include?("unread")
)
Expand Down

0 comments on commit a191ed3

Please sign in to comment.