Skip to content

Commit

Permalink
Fix bug adding a previous existing application (bug was when adding r…
Browse files Browse the repository at this point in the history
…oles).

Added applications test.
  • Loading branch information
dresende committed Dec 21, 2011
1 parent b66af77 commit 3465aae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/roles.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function addApplication(name, roles) {
if (app === null) { if (app === null) {
applications[name] = new Application(name, roles); applications[name] = new Application(name, roles);
} else if (roles && roles.length) { } else if (roles && roles.length) {
applications[name].addRoles(roles); applications[name].addRoles.apply(applications[name], roles);
} }


if (!module.exports.hasOwnProperty(name)) { if (!module.exports.hasOwnProperty(name)) {
Expand All @@ -265,7 +265,7 @@ function addProfile(name, roles) {
if (profile === null) { if (profile === null) {
profiles[name] = new Profile(name, roles); profiles[name] = new Profile(name, roles);
} else if (roles && roles.length) { } else if (roles && roles.length) {
profiles[name].addRoles(roles); profiles[name].addRoles.apply(profiles[name], roles);
} }


if (!module.exports.hasOwnProperty(name)) { if (!module.exports.hasOwnProperty(name)) {
Expand Down
20 changes: 20 additions & 0 deletions test/applications.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,20 @@
var roles = require("./../lib/roles"),
vows = require("vows"),
assert = require("assert");

roles.addApplication("testapp", [ "read", "write" ]);

vows.describe("application").addBatch({
"The test application": {
topic: roles.testapp,
"has 2 roles": function (topic) {
assert.lengthOf(topic.roles, 2);
},
"has role 'read'": function (topic) {
assert.equal(topic.roles[0], "read");
},
"has role 'write'": function (topic) {
assert.equal(topic.roles[1], "write");
}
}
}).export(module);

0 comments on commit 3465aae

Please sign in to comment.