2871: more testing
authorradhika <radhika@curoverse.com>
Mon, 9 Jun 2014 18:00:53 +0000 (14:00 -0400)
committerradhika <radhika@curoverse.com>
Mon, 9 Jun 2014 18:00:53 +0000 (14:00 -0400)
apps/workbench/app/controllers/application_controller.rb
apps/workbench/test/functional/application_controller_test.rb

index 29b76db2566a5e104ede0335a4e6b7c186d7bdb4..eabf3c58efd633bfd8dfe46031522689182a3d8c 100644 (file)
@@ -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
index fbad1d7b302b6306840d7e6da41d301e6b610602..d4adc1c3fca2f2038cd0b9de42ed7f5e5847381c 100644 (file)
@@ -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