Skip to content

Instantly share code, notes, and snippets.

@joshsmith
Created January 7, 2012 00:01
Show Gist options
  • Select an option

  • Save joshsmith/1573130 to your computer and use it in GitHub Desktop.

Select an option

Save joshsmith/1573130 to your computer and use it in GitHub Desktop.
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);
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