Ti.include('../record_db.js');
var db = new RecordDB();
var saved = db.findAll();

test("insert one", function() {
	expect(2);
	var expected = { "id": 1, "weight": "60", "at": "Sun Jul 31 2011" };
	db.deleteAll();
	db.insert(expected);
	var one = db.findById(1);
	notEqual(null, one, "not null");
	equal(QUnit.equiv(one, expected), true, "check one");
});

test("insert two", function() {
	expect(1);
	var expectedAll = [{ "id": 2, "weight": "62", "at": "Tue Aug 02 2011" },
			{ "id": 1, "weight": "60", "at": "Sun Jul 31 2011" }];
	var expectedTwo = { "id": 2, "weight": "62", "at": "Tue Aug 02 2011" };
	db.insert(expectedTwo);
	var all = db.findAll();
	equal(QUnit.equiv(all, expectedAll), true, "check using equal")
});

test("update two", function() {
	expect(1);
	var updatedTwo = { "id": 2, "weight": "65", "at": "Tue Aug 02 2011" };
	db.update(updatedTwo);
	var two = db.findById(2);
	equal(QUnit.equiv(two, updatedTwo), true, "check two");
});

test("delete two", function() {
	expect(1);
	var expectedAll = [{ "id": 1, "weight": "60", "at": "Sun Jul 31 2011" }];
	var two = { "id": 2, "weight": "65", "at": "Tue Aug 02 2011" };
	db.deleteOne(two);
	var all = db.findAll();
	equal(QUnit.equiv(all, expectedAll), true, "check all");	
});

db.restore(saved);
Ti.API.debug(QUnit.jsDump.parse(saved));
db = null;
