[:preload_collections_for_objects, [] ],
[:preload_log_collections_for_objects, [] ],
[:preload_objects_for_dataclass, [] ],
+ [:preload_for_pdhs, [] ],
].each do |input|
test "preload data for empty array input #{input}" do
use_token :active
[:preload_objects_for_dataclass, nil],
[:object_for_dataclass, 'some_dataclass', nil],
[:object_for_dataclass, nil, 'some_uuid'],
+ [:preload_for_pdhs, 'input not an array'],
+ [:preload_for_pdhs, nil],
].each do |input|
test "preload data for wrong type input #{input}" do
use_token :active
[:collections_for_object, 'no-such-uuid' ],
[:log_collections_for_object, 'no-such-uuid' ],
[:object_for_dataclass, 'no-such-uuid' ],
+ [:collection_for_pdh, 'no-such-pdh' ],
].each do |input|
test "get data for no such uuid #{input}" do
use_token :active
objects = ac.send input[0], input[1]
assert objects, 'Expected objects'
assert objects.is_a?(Array), 'Expected a array'
+ assert_empty objects
end
end
end
assert users.size == 3, 'Expected two objects in the preloaded hash'
end
+ test "preload one collection each for given portable_data_hash list" do
+ use_token :active
+
+ ac = ApplicationController.new
+
+ pdh1 = api_fixture('collections')['foo_file']['portable_data_hash']
+ pdh2 = api_fixture('collections')['bar_file']['portable_data_hash']
+
+ pdhs = [pdh1, pdh2]
+ collections = ac.send :preload_for_pdhs, pdhs
+
+ assert collections, 'Expected collections map'
+ assert collections.is_a?(Hash), 'Expected a hash'
+ # Each pdh has more than one collection; however, we should get only one for each
+ assert collections.size == 2, 'Expected two objects in the preloaded collection hash'
+ assert collections[pdh1], 'Expected collections for the passed in pdh #{pdh1}'
+ assert_equal collections[pdh1].size, 1, 'Expected one collection for the passed in pdh #{pdh1}'
+ assert collections[pdh2], 'Expected collections for the passed in pdh #{pdh2}'
+ assert_equal collections[pdh2].size, 1, 'Expected one collection for the passed in pdh #{pdh2}'
+ end
+
test "requesting a nonexistent object returns 404" do
# We're really testing ApplicationController's find_object_by_uuid.
# It's easiest to do that by instantiating a concrete controller.
end
end
end
+
+ [
+ true,
+ false,
+ ].each do |config|
+ test "invoke show with include_accept_encoding_header config #{config}" do
+ Rails.configuration.include_accept_encoding_header_in_api_requests = config
+
+ @controller = CollectionsController.new
+ get(:show, {id: api_fixture('collections')['foo_file']['uuid']}, session_for(:admin))
+
+ assert_equal([['.', 'foo', 3]], assigns(:object).files)
+ end
+ end
end