Skip to content

Instantly share code, notes, and snippets.

@dburles
Created June 3, 2014 04:57
Show Gist options
  • Save dburles/7853d478f36555301317 to your computer and use it in GitHub Desktop.
Save dburles/7853d478f36555301317 to your computer and use it in GitHub Desktop.
Tinytest.add('Working', function(test) {
Books = new Meteor.Collection('books' + test.id);
Authors = new Meteor.Collection('authors' + test.id);
var author1 = Authors.insert({
firstName: 'Charles',
lastName: 'Darwin'
});
var book1 = Books.insert({
authorId: author1,
name: 'On the Origin of Species',
rating: 1
});
// Set up hooks
Hooks.before.update(Books, '$set', 'name', function(userId, doc, fieldNames, modifier, options) {
modifier.$set.rating = 5;
});
Books.update(book1, {
$set: {
name: 'Test',
'dotted.test': 'stuff'
}
});
var book = Books.findOne(book1);
test.equal(book.rating, 5);
Books.update(book1, {
$set: {
dummy: true,
rating: 1
}
});
book = Books.findOne(book1);
test.equal(book.dummy, true);
test.equal(book.rating, 1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment