From 03303390031ae88c9df3a0e14d85550884bb1740 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Mon, 23 May 2011 10:39:09 -0400 Subject: 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/entity_tests.js | 1 - install/ui/test/navigation_tests.js | 9 ++++----- install/ui/webui.js | 2 -- 5 files changed, 18 insertions(+), 26 deletions(-) (limited to 'install') diff --git a/install/ui/ipa.js b/install/ui/ipa.js index 8f11b92df..13c894fa6 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 entity; + }; + + 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 8f98f1fef..ca4658f87 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/entity_tests.js b/install/ui/test/entity_tests.js index c258976f8..41e4d5e47 100644 --- a/install/ui/test/entity_tests.js +++ b/install/ui/test/entity_tests.js @@ -39,7 +39,6 @@ module('entity',{ columns:['uid']}). build(); }; - IPA.start_entities(); }, function(xhr, text_status, error_thrown) { ok(false, "ipa_init() failed: "+error_thrown); diff --git a/install/ui/test/navigation_tests.js b/install/ui/test/navigation_tests.js index 0f8f1be4a..d9bcc8eb6 100644 --- a/install/ui/test/navigation_tests.js +++ b/install/ui/test/navigation_tests.js @@ -20,6 +20,7 @@ module('navigation', { + setup: function() { IPA.ajax_options.async = false; IPA.init( @@ -32,11 +33,14 @@ module('navigation', { } ); } + }); test("Testing IPA.navigation.create().", function() { var entity; + var user_mock_called = false; + var group_mock_called = false; IPA.entity_factories.user = function() { var that = IPA.entity({name: 'user', @@ -59,13 +63,8 @@ test("Testing IPA.navigation.create().", function() { return that; }; - IPA.start_entities(); - - IPA.metadata = {}; var navigation_container = $('