1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class ResourceListTest < ActiveSupport::TestCase
9 reset_api_fixtures :after_each_test, false
11 test 'links_for on a resource list that does not return links' do
13 results = Specimen.all
14 assert_equal [], results.links_for(api_fixture('users')['active']['uuid'])
17 test 'get all items by default' do
20 Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').each do
26 test 'prefetch all items' do
29 Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').each do
35 test 'get limited items' do
38 Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').limit(51).each do
44 test 'get limited items, limit % page_size != 0' do
45 skip "Requires server MAX_LIMIT < 200 which is not currently the default"
48 max_page_size = Collection.
49 where(owner_uuid: 'zzzzz-j7d0g-0201collections').
51 fetch_multiple_pages(false).
53 # Conditions necessary for this test to be valid:
54 assert_operator 200, :>, max_page_size
55 assert_operator 1, :<, max_page_size
56 # Verify that the server really sends max_page_size when asked for max_page_size+1
57 assert_equal max_page_size, Collection.
58 where(owner_uuid: 'zzzzz-j7d0g-0201collections').
59 limit(max_page_size+1).
60 fetch_multiple_pages(false).
63 # Now that we know the max_page_size+1 is in the middle of page 2,
64 # make sure #each returns page 1 and only the requested part of
68 Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').limit(max_page_size+1).each do |item|
70 saw_uuid[item.uuid] = true
72 assert_equal max_page_size+1, a
73 # Ensure no overlap between pages
74 assert_equal max_page_size+1, saw_uuid.size
77 test 'get single page of items' do
80 c = Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').fetch_multiple_pages(false)
85 assert_operator a, :<, 201
86 assert_equal c.result_limit, a
89 test 'get empty set' do
92 where(owner_uuid: 'doesn-texis-tdoesntexistdoe').
93 fetch_multiple_pages(false)
94 # Important: check c.result_offset before calling c.results here.
95 assert_equal 0, c.result_offset
96 assert_equal 0, c.items_available
97 assert_empty c.results
102 c = Collection.with_count('none')
103 assert_nil c.items_available
104 refute_empty c.results
107 test 'cache results across each(&block) calls' do
109 c = Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').with_count('none')
111 x.description = 'foo'
116 # We should get the same objects we modified in the loop above
117 # -- not new objects built from another set of API responses.
118 assert_equal 'foo', x.description
120 assert_equal 201, found