From b00248cc1845bd1b675fe8782934efdec1a4eb2e Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Tue, 25 Jun 2013 20:29:58 -0700 Subject: [PATCH] Add user model docs. --- README.md | 37 ++++++++++++++++++++++++++++++++++++- test/geo-point.test.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dac3c2bb..3b331579 100644 --- a/README.md +++ b/README.md @@ -758,7 +758,42 @@ Various APIs in Asteroid accept type descriptions (eg. [remote methods](#remote- - `Date` - a JavaScript date object - `Buffer` - a node.js Buffer object - [GeoPoint](#geopoint) - an asteroid GeoPoint object. TODO - + +### User Model + +Allow users of your asteroid app to register and authenticate. + + // define a User model + var User = asteroid.createModel( + 'user', + { + email: 'EmailAddress', + password: { + type: 'Password', + min: 4, + max: 26 + } + }, + { + username: 'email', + extend: 'User' + } + ); + + // attach to the memory connector + User.attachTo(memory); + + // create a user + User.create({ + email: 'foo@bar.com', + password: '123456' + }); + + +### Email Model + +Send emails from your asteroid app. + ### REST Router Expose models over rest using the `asteroid.rest` router. diff --git a/test/geo-point.test.js b/test/geo-point.test.js index fafabb69..e794835e 100644 --- a/test/geo-point.test.js +++ b/test/geo-point.test.js @@ -16,4 +16,41 @@ describe('GeoPoint', function() { assert.equal(GeoPoint.distanceBetween(here, there, {type: 'feet'}), 2568169.038886431); }); }); + + describe('GeoPoint()', function(){ + it('Create from string.', function() { + var point = new GeoPoint('1.234,5.678'); + assert.equal(point.lng, 1.234); + assert.equal(point.lat, 5.678); + var point2 = new GeoPoint('1.222, 5.333'); + assert.equal(point2.lng, 1.222); + assert.equal(point2.lat, 5.333); + var point3 = new GeoPoint('1.333, 5.111'); + assert.equal(point3.lng, 1.333); + assert.equal(point3.lat, 5.111); + }); + it('Serialize as string.', function() { + var str = '1.234,5.678'; + var point = new GeoPoint(str); + assert.equal(point.toString(), str); + }); + it('Create from array.', function() { + var point = new GeoPoint([5.555, 6.777]); + assert.equal(point.lng, 5.555); + assert.equal(point.lat, 6.777); + }); + it('Create as Model property', function() { + var Model = asteroid.createModel('geo-model', { + geo: {type: 'GeoPoint'} + }); + + var m = new Model({ + geo: '1.222,3.444' + }); + + assert(m.geo instanceof GeoPoint); + assert.equal(m.geo.lng, 1.222); + assert.equal(m.geo.lat, 3.444); + }); + }); }); \ No newline at end of file