Skip to content

Commit

Permalink
added twi tests to validate that database-loaded records do not appea…
Browse files Browse the repository at this point in the history
…r as changed when calling
  • Loading branch information
xavierlacot committed Jun 26, 2013
1 parent 8b64204 commit bef4258
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Resources/test/query.js
Expand Up @@ -61,32 +61,32 @@
expect(q.getQuery()).toBe('select * from human left outer join city on city.id = human.city_id');
});

it('joli.query.as()', function() {
it('joli.query.as()', function() {
// test without using as()
q = new joli.query().select()
.from('human')
.join('city', 'id', 'human.city_id');

// query validation
expect(q.getQuery()).toBe('select * from human left outer join city on city.id = human.city_id');

// recs should be for humans
recs = q.execute();
expect(recs.length).toBe(1);
human = recs[0];
expect(human.first_name).toBe('Sarah');
expect(human.last_name).toBe('Sure');
expect(human.city_id).toBe(models.city.findOneBy('name', 'New York').get('id'));

// test a projection of the same query using as('city')
q = new joli.query().select('city.*')
.from('human')
.join('city', 'id', 'human.city_id')
.as('city');

// query validation
expect(q.getQuery()).toBe('select city.* from human left outer join city on city.id = human.city_id');

// recs should be for cities
recs = q.execute();
expect(recs.length).toBe(1);
Expand Down Expand Up @@ -198,4 +198,4 @@
* @TODO: add hydratation test methods
*/
});
})();
})();
23 changes: 22 additions & 1 deletion Resources/test/record.js
Expand Up @@ -33,10 +33,31 @@
expect(test.sarah.isChanged()).toBeFalsy();
expect(test.john.isChanged()).toBeFalsy();

// change a record and test its isChanged() method again
test.sarah.set('last_name', 'Married');
expect(test.sarah.isChanged()).toBeTruthy();
test.sarah.save();
expect(test.sarah.isChanged()).toBeFalsy();

// grab a record from the database and check its isChanged() method
var sarah = models.human.findOneBy('first_name', 'Sarah');
expect(sarah.isChanged()).toBeFalsy();

sarah.fromArray({
id: sarah.get('id'),
city_id: sarah.get('city_id'),
first_name: 'Sarah',
last_name: 'Michel'
});
expect(sarah.isChanged()).toBeTruthy();

sarah.fromArray({
id: sarah.get('id'),
city_id: sarah.get('city_id'),
first_name: 'Sarah',
last_name: 'Married'
});
expect(sarah.isChanged()).toBeFalsy();
});

it('joli.record custom methods', function() {
Expand Down Expand Up @@ -78,4 +99,4 @@
expect(count).toEqual(4);
});
});
})();
})();

0 comments on commit bef4258

Please sign in to comment.