starting Address idiom changes

This commit is contained in:
Manuel Araoz 2014-03-11 10:21:26 -03:00
parent 73ceb2e04e
commit ad34fd191d
2 changed files with 8 additions and 2 deletions

View File

@ -10,10 +10,12 @@ Address.parent = parent;
parent.applyEncodingsTo(Address);
Address.prototype.validate = function() {
var answer;
this.doAsBinary(function() {
Address.super(this, 'validate', arguments);
if(this.data.length !== 21) throw new Error('invalid data length');
answer = (this.data.length === 21);
});
return answer;
};
module.exports = require('soop')(Address);

View File

@ -26,7 +26,11 @@ describe('Address', function() {
var b = new Address('11111111111111111111111111122222234');
a.validate.bind(a).should.not.throw(Error);
m.validate.bind(m).should.not.throw(Error);
b.validate.bind(b).should.throw(Error);
b.validate.bind(b).should.not.throw(Error);
a.validate().should.equal(true);
m.validate().should.equal(true);
b.validate().should.equal(false);
});
});