Created
January 7, 2012 00:01
-
-
Save joshsmith/1573130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Company = function (app) { | |
| console.log(app.set('client').host); | |
| this.table = 'companies'; | |
| this.client = app.set('client'); | |
| }; | |
| // Create the company | |
| Company.prototype.create = function(name, contact, email, password, callback) { | |
| this.client.query( | |
| 'INSERT INTO ' + this.table + | |
| ' SET name = ?, contact = ?, email = ?, password = ?,', | |
| [ name, contact, email, password ], | |
| function selectCb(err, results, fields) { | |
| if(err) { | |
| callback(err); | |
| } else { | |
| callback(null, results); | |
| } | |
| } | |
| ); | |
| }; | |
| // Get company with just their email address | |
| Company.prototype.getByEmail = function(email, callback) { | |
| this.client.query( | |
| 'SELECT * FROM ' + this.table + | |
| ' WHERE email = ?', | |
| [ email ], | |
| function selectCb(err, results, fields) { | |
| if(err) { | |
| callback(err); | |
| } else { | |
| callback(null, results); | |
| } | |
| } | |
| ); | |
| }; | |
| module.exports = Company(app); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var should = require('should') | |
| app = require('../fake.js'), | |
| Company = require('./company'); | |
| describe('Company', function(){ | |
| describe('#create()', function() { | |
| it('should return a company id', function(done) { | |
| var company = new Company(); | |
| console.log(company); | |
| company.create('name', 'contact', 'email', 'password', function(err, result) { | |
| if (err) throw new Error(); | |
| if(typeof result.cid === 'undefined') throw new Error(); | |
| result.cid.should.be.a('number'); | |
| done(); | |
| }); | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment