create entities on demand.

fixed changes from code review

Fixed unit tests for entity on demand changes.
This commit is contained in:
Adam Young 2011-05-23 10:39:09 -04:00
parent 0238cb845a
commit 0330339003
5 changed files with 18 additions and 26 deletions

View File

@ -131,7 +131,20 @@ var IPA = ( function () {
}; };
that.get_entity = function(name) { that.get_entity = function(name) {
return that.entities.get(name); var entity = that.entities.get(name);
if (!entity){
var factory = that.entity_factories[name];
try {
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.add_entity = function(entity) {
@ -142,22 +155,6 @@ var IPA = ( function () {
that.entities.remove(name); that.entities.remove(name);
}; };
that.start_entities = function() {
var factory;
var name;
for (name in that.entity_factories) {
factory = that.entity_factories[name];
try {
var entity = factory();
that.add_entity(entity);
entity.init();
} catch (e) {
/*exceptions thrown by builder just mean that entities
are not to be registered. */
}
}
};
that.test_dirty = function(){ that.test_dirty = function(){
if (IPA.current_entity){ if (IPA.current_entity){
var facet_name = IPA.current_facet(IPA.current_entity); var facet_name = IPA.current_facet(IPA.current_entity);

View File

@ -43,7 +43,6 @@ module('details', {
return IPA.entity({name:obj_name, return IPA.entity({name:obj_name,
metadata:IPA.metadata.objects.user}); metadata:IPA.metadata.objects.user});
}; };
IPA.start_entities();
}, },
teardown: function() { teardown: function() {
details_container.remove(); details_container.remove();

View File

@ -39,7 +39,6 @@ module('entity',{
columns:['uid']}). columns:['uid']}).
build(); build();
}; };
IPA.start_entities();
}, },
function(xhr, text_status, error_thrown) { function(xhr, text_status, error_thrown) {
ok(false, "ipa_init() failed: "+error_thrown); ok(false, "ipa_init() failed: "+error_thrown);

View File

@ -20,6 +20,7 @@
module('navigation', { module('navigation', {
setup: function() { setup: function() {
IPA.ajax_options.async = false; IPA.ajax_options.async = false;
IPA.init( IPA.init(
@ -32,11 +33,14 @@ module('navigation', {
} }
); );
} }
}); });
test("Testing IPA.navigation.create().", function() { test("Testing IPA.navigation.create().", function() {
var entity; var entity;
var user_mock_called = false;
var group_mock_called = false;
IPA.entity_factories.user = function() { IPA.entity_factories.user = function() {
var that = IPA.entity({name: 'user', var that = IPA.entity({name: 'user',
@ -59,13 +63,8 @@ test("Testing IPA.navigation.create().", function() {
return that; return that;
}; };
IPA.start_entities();
IPA.metadata = {};
var navigation_container = $('<div id="navigation"/>').appendTo(document.body); var navigation_container = $('<div id="navigation"/>').appendTo(document.body);
var entity_container = $('<div id="content"/>').appendTo(document.body); var entity_container = $('<div id="content"/>').appendTo(document.body);
var user_mock_called = false;
var group_mock_called = false;
var navigation = IPA.navigation({ var navigation = IPA.navigation({
container: navigation_container, container: navigation_container,

View File

@ -143,8 +143,6 @@ $(function() {
$('#loggedinas a').fragment( $('#loggedinas a').fragment(
{'user-facet': 'details', 'user-pkey': IPA.whoami_pkey}, 2); {'user-facet': 'details', 'user-pkey': IPA.whoami_pkey}, 2);
IPA.start_entities();
IPA.nav = create_navigation(); IPA.nav = create_navigation();
IPA.nav.create(); IPA.nav.create();
IPA.nav.update(); IPA.nav.update();