[ARVADOS] updated: 55b94087ff4590c54cf1f43d941c6cb24153dded

git at public.curoverse.com git at public.curoverse.com
Mon Jun 9 11:44:29 EDT 2014


Summary of changes:
 .../app/controllers/application_controller.rb      | 11 ++--
 .../test/functional/application_controller_test.rb | 69 ++++++++++++++++++++++
 2 files changed, 76 insertions(+), 4 deletions(-)

       via  55b94087ff4590c54cf1f43d941c6cb24153dded (commit)
      from  408649cc0e9ad3d30296b0750680fb62fefe6d82 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 55b94087ff4590c54cf1f43d941c6cb24153dded
Author: radhika <radhika at curoverse.com>
Date:   Mon Jun 9 11:43:40 2014 -0400

    2871: add tests for get_n_objects_of_class helper method

diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb
index 7b726b4..3b8aa9a 100644
--- a/apps/workbench/app/controllers/application_controller.rb
+++ b/apps/workbench/app/controllers/application_controller.rb
@@ -499,16 +499,19 @@ class ApplicationController < ActionController::Base
   def get_n_objects_of_class dataclass, size
     @objects_map_for ||= {}
 
+    raise ArgumentError, 'Argument is not a data class' unless dataclass.is_a? Class
+    raise ArgumentError, 'Argument is not a valid limit size' unless (size && size>0)
+
     # if the objects_map_for has a value for this dataclass, and the
     # size used to retrieve those objects is equal, return it
-    size_key = "#{dataclass}_size"
-    if @objects_map_for[dataclass] && @objects_map_for[size_key] &&
+    size_key = "#{dataclass.name}_size"
+    if @objects_map_for[dataclass.name] && @objects_map_for[size_key] &&
         (@objects_map_for[size_key] == size)
-      return @objects_map_for[dataclass]
+      return @objects_map_for[dataclass.name]
     end
 
     @objects_map_for[size_key] = size
-    @objects_map_for[dataclass] = dataclass.limit(size)
+    @objects_map_for[dataclass.name] = dataclass.limit(size)
   end
 
   # helper method to get collections for the given uuid
diff --git a/apps/workbench/test/functional/application_controller_test.rb b/apps/workbench/test/functional/application_controller_test.rb
index 50281f7..8b6270d 100644
--- a/apps/workbench/test/functional/application_controller_test.rb
+++ b/apps/workbench/test/functional/application_controller_test.rb
@@ -102,6 +102,75 @@ class ApplicationControllerTest < ActionController::TestCase
     assert links.size == 0, 'Expected no objects in the preloaded links hash'
   end
 
+  test "get 10 objects of data class user" do
+    use_token :active
+
+    ac = ApplicationController.new
+
+    uuid = api_fixture('users')['active']['uuid']
+
+    dataclass = ArvadosBase.resource_class_for_uuid(uuid)
+    objects = ac.send :get_n_objects_of_class, dataclass, 10
+
+    assert objects, 'Expected objects'
+    assert objects.is_a?(ArvadosResourceList), 'Expected an ArvadosResourceList'
+
+    first_object = objects.first
+    assert first_object, 'Expected at least one object'
+    assert_equal 'User', first_object.class.name, 'Expected user object'
+
+    # invoke it again. this time, the preloaded info will be returned
+    objects = ac.send :get_n_objects_of_class, dataclass, 10
+    assert objects, 'Expected objects'
+    assert_equal 'User', objects.first.class.name, 'Expected user object'
+  end
+
+  test "get objects for incorrect input" do
+    use_token :active
+
+    ac = ApplicationController.new
+
+    assert_raise ArgumentError do
+      ac.send :get_n_objects_of_class, 'User', 10
+    end
+  end
+
+  test "get objects for nil data class" do
+    use_token :active
+
+    ac = ApplicationController.new
+
+    assert_raise ArgumentError do
+      ac.send :get_n_objects_of_class, nil, 10
+    end
+  end
+
+  test "get objects of data class user with no limit specified" do
+    use_token :active
+
+    ac = ApplicationController.new
+
+    uuid = api_fixture('users')['active']['uuid']
+
+    dataclass = ArvadosBase.resource_class_for_uuid(uuid)
+    assert_raise ArgumentError do
+      ac.send :get_n_objects_of_class, dataclass
+    end
+  end
+
+  test "get objects of data class user with incorrect limit size" do
+    use_token :active
+
+    ac = ApplicationController.new
+
+    uuid = api_fixture('users')['active']['uuid']
+
+    dataclass = ArvadosBase.resource_class_for_uuid(uuid)
+    assert_raise ArgumentError do
+      ac.send :get_n_objects_of_class, dataclass, 0
+    end
+  end
+
   test "collections for object" do
     use_token :active
 

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list