3 class ResourceListTest < ActiveSupport::TestCase
5 reset_api_fixtures :after_each_test, false
7 test 'links_for on a resource list that does not return links' do
10 assert_equal [], results.links_for(api_fixture('users')['active']['uuid'])
13 test 'get all items by default' do
16 Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').each do
22 test 'prefetch all items' do
25 Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').each do
31 test 'get limited items' do
34 Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').limit(51).each do
40 test 'get limited items, limit % page_size != 0' do
41 skip "Requires server MAX_LIMIT < 200 which is not currently the default"
44 max_page_size = Collection.
45 where(owner_uuid: 'zzzzz-j7d0g-0201collections').
47 fetch_multiple_pages(false).
49 # Conditions necessary for this test to be valid:
50 assert_operator 200, :>, max_page_size
51 assert_operator 1, :<, max_page_size
52 # Verify that the server really sends max_page_size when asked for max_page_size+1
53 assert_equal max_page_size, Collection.
54 where(owner_uuid: 'zzzzz-j7d0g-0201collections').
55 limit(max_page_size+1).
56 fetch_multiple_pages(false).
59 # Now that we know the max_page_size+1 is in the middle of page 2,
60 # make sure #each returns page 1 and only the requested part of
64 Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').limit(max_page_size+1).each do |item|
66 saw_uuid[item.uuid] = true
68 assert_equal max_page_size+1, a
69 # Ensure no overlap between pages
70 assert_equal max_page_size+1, saw_uuid.size
73 test 'get single page of items' do
76 c = Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').fetch_multiple_pages(false)
81 assert_operator a, :<, 201
82 assert_equal c.result_limit, a
85 test 'get empty set' do
88 where(owner_uuid: 'doesn-texis-tdoesntexistdoe').
89 fetch_multiple_pages(false)
90 # Important: check c.result_offset before calling c.results here.
91 assert_equal 0, c.result_offset
92 assert_equal 0, c.items_available
93 assert_empty c.results
98 c = Collection.with_count('none')
99 assert_nil c.items_available
100 refute_empty c.results