Skip to content

Commit

Permalink
starting Address idiom changes
Browse files Browse the repository at this point in the history
  • Loading branch information
maraoz committed Mar 11, 2014
1 parent 73ceb2e commit ad34fd1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
6 changes: 5 additions & 1 deletion test/test.Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down

0 comments on commit ad34fd1

Please sign in to comment.