3 class ResourceListTest < ActiveSupport::TestCase
5 test 'links_for on a resource list that does not return links' do
8 assert_equal [], results.links_for(api_fixture('users')['active']['uuid'])
11 test 'get all items by default' do
14 Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').each do
20 test 'prefetch all items' do
23 Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').each do
29 test 'get limited items' do
32 Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').limit(51).each do
38 test 'get limited items, limit % page_size != 0' do
39 skip "Requires server MAX_LIMIT < 200 which is not currently the default"
42 max_page_size = Collection.
43 where(owner_uuid: 'zzzzz-j7d0g-0201collections').
45 fetch_multiple_pages(false).
47 # Conditions necessary for this test to be valid:
48 assert_operator 200, :>, max_page_size
49 assert_operator 1, :<, max_page_size
50 # Verify that the server really sends max_page_size when asked for max_page_size+1
51 assert_equal max_page_size, Collection.
52 where(owner_uuid: 'zzzzz-j7d0g-0201collections').
53 limit(max_page_size+1).
54 fetch_multiple_pages(false).
57 # Now that we know the max_page_size+1 is in the middle of page 2,
58 # make sure #each returns page 1 and only the requested part of
62 Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').limit(max_page_size+1).each do |item|
64 saw_uuid[item.uuid] = true
66 assert_equal max_page_size+1, a
67 # Ensure no overlap between pages
68 assert_equal max_page_size+1, saw_uuid.size
71 test 'get single page of items' do
74 c = Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').fetch_multiple_pages(false)
79 assert_operator a, :<, 201
80 assert_equal c.result_limit, a
83 test 'get empty set' do
86 where(owner_uuid: 'doesn-texis-tdoesntexistdoe').
87 fetch_multiple_pages(false)
88 # Important: check c.result_offset before calling c.results here.
89 assert_equal 0, c.result_offset
90 assert_equal 0, c.items_available
91 assert_empty c.results