Merge remote-tracking branch 'origin/open591' into open-master

This commit is contained in:
bwyu
2015-01-16 15:40:44 -08:00
8 changed files with 179 additions and 23 deletions

View File

@@ -72,6 +72,21 @@ define(
}
// Custom registration function for extensions of category "runs"
function registerRun(extension) {
if (typeof extension === 'function') {
// Prepend dependencies, and schedule to run
app.run((extension.depends || []).concat([extension]));
} else {
// If it's not a function, no implementation was given
$log.warn([
"Cannot register run extension from ",
(extension.bundle || {}).path,
"; no implementation."
].join(""));
}
}
// Custom registration function for extensions of category "route"
function registerRoute(extension) {
var route = Object.create(extension);
@@ -107,7 +122,7 @@ define(
// Utility; create a function which converts another function
// (which acts on single objects) to one which acts upon arrays.
function mapUpon(func) {
return function(array) {
return function (array) {
return array.map(func);
};
}
@@ -121,6 +136,7 @@ define(
directives: mapUpon(new CustomRegistrar("directive")),
controllers: mapUpon(new CustomRegistrar("controller")),
services: mapUpon(new CustomRegistrar("service")),
runs: mapUpon(registerRun),
components: registerComponents
};
}

View File

@@ -20,7 +20,8 @@ define(
"directive",
"service",
"constant",
"config"
"config",
"run"
]);
mockLog = jasmine.createSpyObj("$log", [
@@ -39,6 +40,7 @@ define(
expect(customRegistrars.services).toBeTruthy();
expect(customRegistrars.routes).toBeTruthy();
expect(customRegistrars.constants).toBeTruthy();
expect(customRegistrars.runs).toBeTruthy();
});
it("invokes built-in functions on the app", function () {
@@ -58,6 +60,11 @@ define(
expect(mockApp.constant.calls.length).toEqual(0);
customRegistrars.constants([{ key: "a", value: "b" }, { key: "b", value: "c" }, { key: "c", value: "d" }]);
expect(mockApp.constant.calls.length).toEqual(3);
expect(mockApp.run.calls.length).toEqual(0);
customRegistrars.runs([jasmine.createSpy("a"), jasmine.createSpy("a"), jasmine.createSpy("a")]);
expect(mockApp.run.calls.length).toEqual(3);
});
it("warns when keys are not defined, then skips", function () {
@@ -81,6 +88,8 @@ define(
customRegistrars.constants([{ }, { }, { }]);
expect(mockApp.constant.calls.length).toEqual(0);
expect(mockLog.warn.calls.length).toEqual(9);
// Notably, keys are not needed for run calls
});
it("allows routes to be registered", function () {
@@ -126,6 +135,14 @@ define(
expect(customRegistrars.components).toBeTruthy();
customRegistrars.components([]);
});
it("warns if no implementation is provided for runs", function () {
// Verify precondition
expect(mockLog.warn).not.toHaveBeenCalled();
customRegistrars.runs([{ something: "that is not a function"}]);
expect(mockLog.warn).toHaveBeenCalledWith(jasmine.any(String));
expect(mockApp.run).not.toHaveBeenCalled();
});
});
}
);