check_question_response_paging

in spec/spec_helper.rb [286:313]


def check_question_response_paging(thread, hash, resp_skip=0, resp_limit=nil, is_json=false, recursive=false)
  all_responses = thread.root_comments.sort({"sk" => 1}).to_a
  endorsed_responses, non_endorsed_responses = all_responses.partition { |resp| resp.endorsed }

  hash["endorsed_responses"].length.should == endorsed_responses.length
  hash["endorsed_responses"].each_with_index do |response_hash, i|
    check_comment(endorsed_responses[i], response_hash, is_json, recursive)
  end

  hash["non_endorsed_resp_total"] == non_endorsed_responses.length
  expected_non_endorsed_responses = resp_limit.nil? ?
      non_endorsed_responses.drop(resp_skip) :
      non_endorsed_responses.drop(resp_skip).take(resp_limit)
  hash["non_endorsed_responses"].length.should == expected_non_endorsed_responses.length
  hash["non_endorsed_responses"].each_with_index do |response_hash, i|
    check_comment(expected_non_endorsed_responses[i], response_hash, is_json, recursive)
  end
  total_responses = endorsed_responses.length + non_endorsed_responses.length
  hash["resp_total"].should == total_responses

  hash["resp_skip"].to_i.should == resp_skip
  if resp_limit.nil?
    hash["resp_limit"].should be_nil
  else
    hash["resp_limit"].to_i.should == resp_limit
  end
end