Permalink
Browse files

updates

  • Loading branch information...
1 parent 9c20b76 commit 134cb85c2f6481c22ab1b7dcfa9897163d97103d @drewlesueur committed Apr 26, 2011
Showing with 40 additions and 30 deletions.
  1. +2 −0 README.md
  2. +38 −30 test.js
View
@@ -1 +1,3 @@
see `test.coffee` for how to use
+
+`npm install mysql-helper`
View
@@ -1,25 +1,30 @@
(function() {
- var Client, MySqlHelper, client, config, createTable, db, drews, dropTable, insertRow, queryInsert, queryUpdate, updateRow, useDb, _;
+ var Client, MySqlHelper, client, config, createTable, db, dropTable, insertRow, queryInsert, queryUpdate, updateRow, useDb, _;
_ = require("underscore");
config = require("./config");
Client = require("mysql").Client;
- drews = require("drews-mixins");
- _.mixin(drews);
+ require("drews-mixins")(_);
MySqlHelper = require("mysql-helper").MySqlHelper;
client = new Client();
client.user = config.user;
client.password = config.password;
client.host = config.host;
- console.log(config.user, config.password, config.host);
client.connect();
db = new MySqlHelper(client);
useDb = function(done) {
- db.query("USE " + config.db);
- return done();
+ return db.query("USE " + config.db, function(err) {
+ return done(err);
+ });
+ };
+ dropTable = function(done) {
+ return db.query("drop table if exists tests", function(err) {
+ _.assertEqual(err, null, "should drop table");
+ return done(err);
+ });
};
createTable = function(done) {
- return db.query("CREATE TABLE tests (\n id integer,\n name varchar(255),\n email varchar(255)\n)", function(err) {
- _.assertEqual(err, null, "should not error creating db");
+ return db.query("CREATE TABLE tests (\n id integer auto_increment primary key,\n name varchar(255),\n email varchar(255)\n)", function(err) {
+ _.assertEqual(err, null, "should not error creating table");
return done();
});
};
@@ -29,17 +34,20 @@
'email': "drewalex@gmail.com"
}, function(err) {
_.assertEqual(err, null, "no error on insert");
- return done(err, results);
+ return done(err);
});
};
queryInsert = function(done) {
return db.query("SELECT * FROM tests where name=?", ['drew'], function(err, results) {
+ var eq, expectedRow;
_.assertEqual(err, null, "querying should not have error");
- _.assertEqual(_.isEqual(results[0], {
- 'id': '1',
- 'name': 'drew',
+ expectedRow = {
+ 'id': 1,
+ 'name': 'Drew',
email: 'drewalex@gmail.com'
- }), true);
+ };
+ eq = _.isEqual(results[0], expectedRow);
+ _.assertEqual(eq, true, "querying should get expected results");
return done(err);
});
};
@@ -55,36 +63,36 @@
queryUpdate = function(done) {
var aterciopeladosResults, drewsResults;
drewsResults = function(done) {
- db.query("SELECT * FROM tests where name=?", ['drew'], function(err, results) {});
- _.assertEqual(err, null, "querying should not have error");
- _.assertEqual(results.length, null, "no results with drew now");
- return done(err, results);
+ return db.query("SELECT * FROM tests where name=?", ['drew'], function(err, results) {
+ _.assertEqual(err, null, "querying drews results should not have error");
+ _.assertEqual(results.length, 0, "no results with drew now");
+ return done(err, results);
+ });
};
aterciopeladosResults = function(done) {
- db.query("SELECT * FROM tests where name=?", ['drew'], function(err, results) {});
- _.assertEqual(err, null, "querying should not have error");
- _.assertEqual(results.length, null, "no results with drew now");
- return done(err, results);
+ return db.query("SELECT * FROM tests where name=?", ['aterciopelados'], function(err, results) {
+ _.assertEqual(err, null, "querying aterciopelados should not have error");
+ _.assertEqual(results.length, 1, "no results with drew now");
+ return done(err, results);
+ });
};
return _.parallel([drewsResults, aterciopeladosResults], function(err, results) {
var atercios;
_.assertEqual(err, null, "getting results no error");
- _.assertEqual(resutls[0], null, "drew is no longer there");
+ _.assertEqual(results[0].length, 0, "drew is no longer there");
atercios = _.isEqual(results[1][0], {
- id: '1',
+ id: 1,
name: 'Aterciopelados',
email: 'drewalex@gmail.com'
});
+ console.log(results[1][0]);
_.assertEqual(atercios, 1);
return done(err);
});
};
- dropTable = function(done) {
- return db.query("DROP TABLE tests", function(err) {
- return _.assertEqual(err, null, "should drop table");
- });
- };
- _.series([createTable, insertRow, queryInsert, updateRow, queryUpdate, dropTable], function(err, results) {
- return console.log("tests done");
+ _.series([useDb, dropTable, createTable, insertRow, queryInsert, updateRow, queryUpdate, dropTable], function(err, results) {
+ console.log("tests done");
+ console.log("" + (_.getAssertCount()) + " tests ran\n" + (_.getPassCount()) + " tests passed");
+ return client.end();
});
}).call(this);

0 comments on commit 134cb85

Please sign in to comment.