# helper method to get collections for the given uuid
helper_method :collections_for_object
def collections_for_object uuid
+ raise ArgumentError, 'No input argument' unless uuid
preload_collections_for_objects([uuid])
@all_collections_for[uuid] ||= []
end
# helper method to get log collections for the given log
helper_method :log_collections_for_object
def log_collections_for_object log
+ raise ArgumentError, 'No input argument' unless log
+
preload_log_collections_for_objects([log])
uuid = log
# helper method to get object of a given dataclass and uuid
helper_method :object_for_dataclass
def object_for_dataclass dataclass, uuid
+ raise ArgumentError, 'No input argument dataclass' unless (dataclass && uuid)
preload_objects_for_dataclass(dataclass, [uuid])
@objects_for[uuid]
end
def preload_objects_for_dataclass dataclass, uuids
@objects_for ||= {}
+ raise ArgumentError, 'Argument is not a data class' unless dataclass.is_a? Class
raise ArgumentError, 'Argument is not an array' unless uuids.is_a? Array
+
return @all_collections_for if uuids.empty?
# if already preloaded for all of these uuids, return
assert links.size == 0, 'Expected no links'
end
- test "links for nil object" do
- use_token :active
-
- ac = ApplicationController.new
-
- assert_raise ArgumentError do
- ac.send :links_for_object, nil
- end
- end
-
test "preload links for objects and uuids" do
use_token :active
[ [: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 links for wrong type input #{input}" do
+ test "preload data for wrong type input #{input}" do
use_token :active
ac = ApplicationController.new
- assert_raise ArgumentError do
- ac.send input[0], input[1]
+ 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