Skip to content

Commit

Permalink
Some structures require a key
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed May 12, 2011
1 parent 667bca1 commit c6dfba5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var EventEmitter = require('events').EventEmitter;
*/

var Channel = exports.Channel = function (client, channel_name) {
if (!channel_name) {
throw new Error('A channel key is required');
}
this.name = channel_name;
this.setClient(client);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ Structure.prototype.extend = function (methods) {
var structure = function (client, key, namespace, init_args) {
this.client = client;
this.namespace = namespace || '';
if (!key) {
throw new Error('A key is required');
}
if (Array.isArray(key)) {
key = key.join(':');
}
Expand Down
15 changes: 14 additions & 1 deletion test/structure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var redback = require('redback'),
Hash = redback.Hash,
List = redback.List;

var hash = new Hash(), list = new List(), structure = new Structure();
var hash = new Hash(null, 'hash'), list = new List(null, 'list'), structure = new Structure(null, 'structure');

module.exports = {

Expand Down Expand Up @@ -44,6 +44,19 @@ module.exports = {
assert.equal('bar', hash.bar());
assert.ok(typeof structure.bar === 'undefined');
assert.ok(typeof list.bar === 'undefined');
},

'test creating a structure with no key': function () {
var structures = [
'List','Hash','Set','SortedSet','CappedList','DensitySet',
'Channel','KeyPair','SocialGraph'
];

structures.forEach(function (structure) {
assert.throws(function () {
redback['create' + Structure]();
});
});
}

}

0 comments on commit c6dfba5

Please sign in to comment.