Permalink
Browse files

tests pass\!

  • Loading branch information...
1 parent 80a4bd9 commit ccc777fe4a20c0406514f6108c8a74528488d322 @drewlesueur committed Apr 26, 2011
Showing with 34 additions and 28 deletions.
  1. +34 −28 test.coffee
View
@@ -1,34 +1,39 @@
_ = require "underscore"
+console.log _
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() #is this sync or something?
db = new MySqlHelper client
useDb = (done) ->
- db.query "USE #{config.db}"
- done()
+ db.query "USE #{config.db}", (err) ->
+ done(err)
+dropTable = (done) ->
+ db.query """
+ drop table if exists tests
+ """, (err) ->
+ _.assertEqual err, null, "should drop table"
+ done err
createTable = (done) ->
db.query """
CREATE TABLE tests (
- id integer,
+ id integer auto_increment primary key,
name varchar(255),
email varchar(255)
)
""", (err) ->
- _.assertEqual err, null, "should not error creating db"
+ _.assertEqual err, null, "should not error creating table"
done()
insertRow = (done) ->
@@ -37,12 +42,15 @@ insertRow = (done) ->
'email': "drewalex@gmail.com"
}, (err) ->
_.assertEqual err, null, "no error on insert"
- done err, results
+ done err
queryInsert = (done) ->
db.query "SELECT * FROM tests where name=?", ['drew'], (err, results) ->
_.assertEqual err, null, "querying should not have error"
- _.assertEqual _.isEqual(results[0], {'id': '1', 'name': 'drew', email: 'drewalex@gmail.com'}), true
+ expectedRow = {'id': 1, 'name': 'Drew', email: 'drewalex@gmail.com'}
+ eq = _.isEqual results[0], expectedRow
+ _.assertEqual eq, true, "querying should get expected results"
+
done err
updateRow = (done) ->
@@ -53,41 +61,39 @@ queryUpdate = (done) ->
drewsResults = (done) ->
db.query "SELECT * FROM tests where name=?", ['drew'], (err, results) ->
- _.assertEqual err, null, "querying should not have error"
- _.assertEqual results.length, null, "no results with drew now"
- done err, results
+ _.assertEqual err, null, "querying drews results should not have error"
+ _.assertEqual results.length, 0, "no results with drew now"
+ done err, results
aterciopeladosResults = (done) ->
- db.query "SELECT * FROM tests where name=?", ['drew'], (err, results) ->
- _.assertEqual err, null, "querying should not have error"
- _.assertEqual results.length, null, "no results with drew now"
- done err, results
+ db.query "SELECT * FROM tests where name=?", ['aterciopelados'], (err, results) ->
+ _.assertEqual err, null, "querying aterciopelados should not have error"
+ _.assertEqual results.length, 1, "no results with drew now"
+ done err, results
_.parallel [drewsResults, aterciopeladosResults], (err, results) ->
_.assertEqual err, null, "getting results no error"
- _.assertEqual resutls[0], null, "drew is no longer there"
- atercios = _.isEqual results[1][0], {id: '1', name: 'Aterciopelados', email: 'drewalex@gmail.com'}
+ _.assertEqual results[0].length, 0, "drew is no longer there"
+ atercios = _.isEqual results[1][0], {id: 1, name: 'Aterciopelados', email: 'drewalex@gmail.com'}
+ console.log results[1][0]
_.assertEqual atercios, 1
-
done err
-
-dropTable = (done) ->
- db.query """
- DROP TABLE tests
- """, (err) ->
- _.assertEqual err, null, "should drop table"
-
-
-
_.series [
+ useDb
+ dropTable
createTable
insertRow
queryInsert
updateRow
queryUpdate
dropTable
], (err, results) ->
+
console.log "tests done"
+ console.log """
+ #{_.getAssertCount()} tests ran
+ #{_.getPassCount()} tests passed
+ """

0 comments on commit ccc777f

Please sign in to comment.