+ assert links.is_a?(Hash), 'Expected a hash'
+ assert links.size == 3, 'Expected two objects in the preloaded links hash'
+ assert links[link1_head_uuid], 'Expected links for the passed in link head_uuid'
+ assert links[link2_object_uuid], 'Expected links for the passed in object uuid'
+ assert links[link3_head_uuid], 'Expected links for the passed in link head_uuid'
+
+ # invoke again for this same input. this time, the preloaded data will be returned
+ links = ac.send :preload_links_for_objects, uuids
+ assert links, 'Expected links'
+ assert links.is_a?(Hash), 'Expected a hash'
+ assert links.size == 3, 'Expected two objects in the preloaded links hash'
+ assert links[link1_head_uuid], 'Expected links for the passed in link head_uuid'
+ end
+
+ [ [:preload_links_for_objects, [] ],
+ [:preload_collections_for_objects, [] ],
+ [:preload_log_collections_for_objects, [] ],
+ [:preload_objects_for_dataclass, [] ],
+ ].each do |input|
+ test "preload data for empty array input #{input}" do
+ use_token :active
+
+ ac = ApplicationController.new
+
+ if input[0] == :preload_objects_for_dataclass
+ objects = ac.send input[0], @user_dataclass, input[1]
+ else
+ objects = ac.send input[0], input[1]
+ end
+
+ assert objects, 'Expected objects'
+ assert objects.is_a?(Hash), 'Expected a hash'
+ assert objects.size == 0, 'Expected no objects in the preloaded hash'
+ end
+ end
+
+ [ [:preload_links_for_objects, 'input not an array'],
+ [:preload_links_for_objects, nil],
+ [:links_for_object, nil],
+ [:preload_collections_for_objects, 'input not an array'],
+ [:preload_collections_for_objects, nil],
+ [:collections_for_object, nil],
+ [:preload_log_collections_for_objects, 'input not an array'],
+ [:preload_log_collections_for_objects, nil],
+ [:log_collections_for_object, nil],
+ [:preload_objects_for_dataclass, 'input not an array'],
+ [:preload_objects_for_dataclass, nil],
+ [:object_for_dataclass, 'some_dataclass', nil],
+ [:object_for_dataclass, nil, 'some_uuid'],
+ ].each do |input|
+ test "preload data for wrong type input #{input}" do
+ use_token :active
+
+ ac = ApplicationController.new
+
+ if input[0] == :object_for_dataclass
+ assert_raise ArgumentError do
+ ac.send input[0], input[1], input[2]
+ end
+ else
+ assert_raise ArgumentError do
+ ac.send input[0], input[1]
+ end
+ end
+ end
+ end
+
+ [ [:links_for_object, 'no-such-uuid' ],
+ [:collections_for_object, 'no-such-uuid' ],
+ [:log_collections_for_object, 'no-such-uuid' ],
+ [:object_for_dataclass, 'no-such-uuid' ],
+ ].each do |input|
+ test "get data for no such uuid #{input}" do
+ use_token :active
+
+ ac = ApplicationController.new
+
+ if input[0] == :object_for_dataclass
+ object = ac.send input[0], @user_dataclass, input[1]
+ assert_not object, 'Expected no object'
+ else
+ objects = ac.send input[0], input[1]
+ assert objects, 'Expected objects'
+ assert objects.is_a?(Array), 'Expected a array'
+ end
+ end