Skip to content

Commit

Permalink
MongooseBuffer should cast numbers as well
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Jan 23, 2013
1 parent f108ace commit 79e740b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/schema/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ SchemaBuffer.prototype.cast = function (value, doc, init) {
return new MongooseBuffer(value.value(true), [this.path, doc]);
}

if ('string' === typeof value || Array.isArray(value)) {
var type = typeof value;
if ('string' == type || 'number' == type || Array.isArray(value)) {
return new MongooseBuffer(value, [this.path, doc]);
}

Expand Down
4 changes: 3 additions & 1 deletion test/types.buffer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var UserBuffer = new Schema({

describe('types.buffer', function(){

it('test that a mongoose buffer behaves and quacks like an buffer', function(done){
it('test that a mongoose buffer behaves and quacks like a buffer', function(done){
var a = new MongooseBuffer;

assert.ok(a instanceof Buffer);
Expand All @@ -49,10 +49,12 @@ describe('types.buffer', function(){
var a = new MongooseBuffer([195, 188, 98, 101, 114]);
var b = new MongooseBuffer("buffer shtuffs are neat");
var c = new MongooseBuffer('aGVsbG8gd29ybGQ=', 'base64');
var d = new MongooseBuffer(0);

assert.equal(a.toString('utf8'), 'über');
assert.equal(b.toString('utf8'), 'buffer shtuffs are neat');
assert.equal(c.toString('utf8'), 'hello world');
assert.equal(d.toString('utf8'), '');
done();
});

Expand Down

0 comments on commit 79e740b

Please sign in to comment.