On 05/23/2011 12:06 PM, Endi Sukma Dewata wrote:
On 5/23/2011 9:42 AM, Adam Young wrote:
Patch 227 is the automount patch that I still am not ready to submit.
This patch stands alone.

A few issues in IPA.get_entity():

1. It executes that.entities.get() twice. The result of the first
   invocation can be stored in a variable and reused later. The result
   of the factory() invocation can be assigned to the same variable.

2. It executes factory = that.entity_factories[name] twice. The second
   one can be removed.

Other than that it's ACKed and can be pushed after fixing the above issues.

Now with fixed unit tests
From 55c3f6db2b7a297192622662e26ee9b22bc724a3 Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Mon, 23 May 2011 10:39:09 -0400
Subject: [PATCH] create entities on demand. fixed changes from code review

Fixed unit tests for entity on demand changes.
---
 install/ui/ipa.js                   |   31 ++++++++++++++-----------------
 install/ui/test/details_tests.js    |    1 -
 install/ui/test/navigation_tests.js |    4 +++-
 install/ui/webui.js                 |    2 --
 4 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/install/ui/ipa.js b/install/ui/ipa.js
index 8f11b92df2e86adc61758da1790e900e562f2510..72365cfe3c08d1a52f79cc686fa246b30f9a09f2 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -131,31 +131,28 @@ var IPA = ( function () {
     };
 
     that.get_entity = function(name) {
-        return that.entities.get(name);
-    };
-
-    that.add_entity = function(entity) {
-        that.entities.put(entity.name, entity);
-    };
-
-    that.remove_entity = function(name) {
-        that.entities.remove(name);
-    };
-
-    that.start_entities = function() {
-        var factory;
-        var name;
-        for (name in that.entity_factories) {
-            factory = that.entity_factories[name];
+        var entity = that.entities.get(name);
+        if (!entity){
+            var factory = that.entity_factories[name];
             try {
-                var entity = factory();
+                entity = factory();
                 that.add_entity(entity);
                 entity.init();
             } catch (e) {
                 /*exceptions thrown by builder just mean that entities
                   are not to be registered. */
+                return null;
             }
         }
+        return that.entities.get(name);
+    };
+
+    that.add_entity = function(entity) {
+        that.entities.put(entity.name, entity);
+    };
+
+    that.remove_entity = function(name) {
+        that.entities.remove(name);
     };
 
     that.test_dirty = function(){
diff --git a/install/ui/test/details_tests.js b/install/ui/test/details_tests.js
index 8f98f1fef33e19ba8400266ee7faf632da40764c..ca4658f8712f7925001c8a59d4de3bb6ae5aeb3a 100644
--- a/install/ui/test/details_tests.js
+++ b/install/ui/test/details_tests.js
@@ -43,7 +43,6 @@ module('details', {
                 return IPA.entity({name:obj_name,
                                    metadata:IPA.metadata.objects.user});
             };
-        IPA.start_entities();
     },
     teardown: function() {
         details_container.remove();
diff --git a/install/ui/test/navigation_tests.js b/install/ui/test/navigation_tests.js
index 0f8f1be4a886074ca6946316f356dc9b0c6aadd4..c6d696fb87bb638452ec17e2a7a14982727dd79e 100644
--- a/install/ui/test/navigation_tests.js
+++ b/install/ui/test/navigation_tests.js
@@ -59,7 +59,9 @@ test("Testing IPA.navigation.create().", function() {
         return that;
     };
 
-    IPA.start_entities();
+    IPA.get_entity('user');
+    IPA.get_entity('group');
+
 
     IPA.metadata = {};
     var navigation_container = $('<div id="navigation"/>').appendTo(document.body);
diff --git a/install/ui/webui.js b/install/ui/webui.js
index b9d050c29a0c93d96d242c16b873e3825ed82a95..00c35b459d0f649b773e308916fdc1a845c6ec4e 100644
--- a/install/ui/webui.js
+++ b/install/ui/webui.js
@@ -143,8 +143,6 @@ $(function() {
         $('#loggedinas a').fragment(
             {'user-facet': 'details', 'user-pkey': IPA.whoami_pkey}, 2);
 
-        IPA.start_entities();
-
         IPA.nav = create_navigation();
         IPA.nav.create();
         IPA.nav.update();
-- 
1.7.5.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to