Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"ApplicationInstance.setupForwardDependencies adds resolver functions to external apps";
var randomTag = 'random'+Math.random(),
randomName = 'randomName'+Math.random(),
externalApps = {};
externalApps[randomName] = application.any(randomTag);
var app_dict = {
'app1':application.app({'provides':[randomTag]}).instantiate('app1')
},
externalApps
ourAppOptions = {
'external_apps':externalApps,
'models':{'FakeModel':models.model({'someDep':models.ForeignKey(models.dep(randomName, randomName))})}
};
app = application.app(ourAppOptions),
appInstance = app.instantiate(randomName+Math.random());
appInstance.setupForwardDependencies(app_dict);
assert.equal(app_dict.app1.resolvers[randomName].length, 1);
assert.isInstance(app_dict.app1.resolvers[randomName][0], Function);
var randomResult = Math.random();
app_dict.app1.resolvers[randomName][0](randomResult);
// now this is quite a reach...
assert.equal(appInstance.app.models.FakeModel.opts.someDep.dependency.model, randomResult);
},
function(assert) {
function(assert) {
"application.app returns an instance of Application with opts";
var options = {};
for(var i = 0, len = Math.random()*10+1; i < len; ++i) {
options['random'+i] = i;
}
var app = application.app(options);
assert.isInstance(app, application.Application);
for(var name in options) {
assert.equal(options[name], app[name]);
}
},
function(assert) {
function(assert) {
"ApplicationInstance.resolveAppDependency throws an error if it cannot find an appropriate app";
var randomTag = 'random'+Math.random(),
app_dict = {
'app1':application.app({'provides':[randomTag]}).instantiate('app1')
},
appInstance = application.app({}).instantiate(Math.random());
assert.throws(Error, function() {
appInstance.resolveAppDependency(application.primary(randomTag), app_dict);
});
},
function(assert) {
function(assert) {
"urls.app should grab the appropriate app instance and update it's child routes appropriately";
var randomName = 'random'+Math.random(),
routes = escaperoute.routes('',
url('^awesome/$', function() {
assert.isInstance(this, application.ApplicationInstance);
}, randomName)
),
app = application.app({
'urls':routes,
}),
appInstance = app.instantiate(randomName, app),
result = urls.app('something/', Math.random(), appInstance);
assert.isInstance(result, escaperoute.Route);
assert.isInstance(result.target, escaperoute.Router);
assert.strictEqual(result.target, appInstance.urls);
assert.isInstance(appInstance.urls, escaperoute.Router);
assert.equal(appInstance.urls.routes[0].name, [randomName, randomName].join(':'));
result.target.match('awesome/')();
}
);
function(assert) {
"application.app.instantiate returns a new named ApplicationInstance";
var options = {},
randomName = 'random'+Math.random();
for(var i = 0, len = Math.random()*10+1; i < len; ++i) {
options['random'+i] = i;
}
var app = application.app(options),
appInstance = app.instantiate(randomName);
assert.isInstance(appInstance, application.ApplicationInstance);
assert.equal(appInstance.name, randomName);
assert.strictEqual(appInstance.app, app);
},
function(assert) {
function(assert) {
"ApplicationInstance.resolveModels triggers any resolvers with the name of an instantiated model class";
var randomTag = 'random'+Math.random(),
randomName = 'randomName'+Math.random(),
ourAppOptions = {
'models':{'FakeModel':models.model({'field':models.CharField({'max_length':255})})}
};
app = application.app(ourAppOptions),
appInstance = app.instantiate(randomName+Math.random()),
trigger = 0;
appInstance.resolvers = {
'FakeModel':[function(model) {
assert.strictEqual(appInstance.models.FakeModel, model);
++trigger;
}]
};
appInstance.resolveModels();
assert.equal(trigger, 1);
}
);