--- a/test/basic-filters.js Wed Dec 12 19:41:08 2012 +0900
+++ b/test/basic-filters.js Thu Dec 13 03:19:14 2012 +0900
-var a, b, c, col, otherCol;
+var a, b, c, col, otherCol, additions, removals, resets;
module('Backbone.Shard', {
c = new Backbone.Model({data: 'c'});
col = new Backbone.Collection([a, b, c]);
otherCol = new Backbone.Collection();
filter: function() { return false; }
shard.on('add', function() {
}).on('remove', function() {
filter: function() { return true; }
shard.on('add', function() {
}).on('remove', function() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/changing-models.js Thu Dec 13 03:19:14 2012 +0900
+var a, b, c, d, col, additions, removals, changes, likechanges, readShard, unreadShard;
+module('Backbone.Shard', {
+ a = new Backbone.Model({data: 'a', read: true, like: false});
+ b = new Backbone.Model({data: 'b', read: true, like: false});
+ c = new Backbone.Model({data: 'c', read: false, like: false});
+ d = new Backbone.Model({data: 'd', read: false, like: false});
+ col = new Backbone.Collection([a, b, c, d]);
+ readShard = new Backbone.Shard({
+ filter: function(model) { return model.get('read'); }
+ unreadShard = new Backbone.Shard({
+ filter: function(model) { return !model.get('read'); }
+ additions = {read: 0, unread: 0};
+ removals = {read: 0, unread: 0};
+ changes = {read: 0, unread: 0};
+ likechanges = {read: 0, unread: 0};
+ readShard.on('add', function() {
+ }).on('remove', function() {
+ }).on('change', function() {
+ }).on('change:like', function() {
+ unreadShard.on('add', function() {
+ }).on('remove', function() {
+ }).on('change', function() {
+ }).on('change:like', function() {
+test('Updating model attributes not used in shard filter', function() {
+ equal(likechanges.read, 1, 'change:like triggered in readShard');
+ equal(likechanges.unread, 0, 'change:like not triggered in unreadShard');
+test('Updating model attributes used in shard filter', function() {
+ deepEqual(readShard.size(), 1, 'removes from readShard');
+ equal(removals.read, 1, '... and triggers remove event');
+ equal(unreadShard.size(), 3, 'adds to unreadShard');
+ equal(additions.unread, 1, '... and triggers add event');
--- a/test/index.html Wed Dec 12 19:41:08 2012 +0900
+++ b/test/index.html Thu Dec 13 03:19:14 2012 +0900
<script src="basic-filters.js"></script>
<script src="sensible-filters.js"></script>
<script src="underscore-methods.js"></script>
+ <script src="changing-models.js"></script>