From: radhika Date: Mon, 9 Jun 2014 18:00:53 +0000 (-0400) Subject: 2871: more testing X-Git-Tag: 1.1.0~2563^2~7 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/dd6e25d53f9cf02f91b419584ff4c331e0618a24?ds=sidebyside;hp=400829b3835f0a129116a2eed926d12a0636aeab 2871: more testing --- diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb index 29b76db256..eabf3c58ef 100644 --- a/apps/workbench/app/controllers/application_controller.rb +++ b/apps/workbench/app/controllers/application_controller.rb @@ -517,6 +517,7 @@ class ApplicationController < ActionController::Base # 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 @@ -548,6 +549,8 @@ class ApplicationController < ActionController::Base # 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 @@ -596,6 +599,7 @@ class ApplicationController < ActionController::Base # 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 @@ -605,7 +609,9 @@ class ApplicationController < ActionController::Base 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 diff --git a/apps/workbench/test/functional/application_controller_test.rb b/apps/workbench/test/functional/application_controller_test.rb index fbad1d7b30..d4adc1c3fc 100644 --- a/apps/workbench/test/functional/application_controller_test.rb +++ b/apps/workbench/test/functional/application_controller_test.rb @@ -33,16 +33,6 @@ class ApplicationControllerTest < ActionController::TestCase 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 @@ -87,20 +77,31 @@ class ApplicationControllerTest < ActionController::TestCase [ [: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