Skip to content

Commit

Permalink
collapsed tests so there are less failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Woodall committed Jul 1, 2011
1 parent 6f7b09f commit 7ad57d7
Showing 1 changed file with 47 additions and 37 deletions.
84 changes: 47 additions & 37 deletions tests/test.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
$(document).ready(function() {
module("localStorage");

module("localStorage");

var Library = Backbone.Collection.extend({
localStorage: new window.Store("libraryStore")
});

var library = new Library();

var attrs = {
title : 'The Tempest',
author : 'Bill Shakespeare',
length : 123
};

var Library = Backbone.Collection.extend({
localStorage: new window.Store("libraryStore")

// is the problem with my library that is has no model reference?
});

test("collection read", function() {
library.fetch();
equals(library.length, 0);
});
var library = new Library();

var attrs = {
title : 'The Tempest',
author : 'Bill Shakespeare',
length : 123
};

// Make sure there is no library collection when we start

var killStorage = function (name) {
for (var i = 0; i < localStorage.length; i++) {
var key = localStorage.key(i);
if (key.indexOf(name) !== -1) {
localStorage.removeItem(key);
}
}

};

// read from the library object that shouldn't exist when we start
test("collection", function() {
killStorage('libraryStore');
library.fetch();
equals(library.length, 0, 'empty read');

library.create(attrs);
equals(library.length, 1, 'one item added');
equals(library.first().get('title'), 'The Tempest', 'title was read');
equals(library.first().get('author'), 'Bill Shakespeare', 'author was read');
equals(library.first().get('length'), 123, 'length was read');

test("collection create", function() {
library.create(attrs);
equals(library.length, 1);
equals(library.first().get('title'), 'The Tempest');
equals(library.first().get('author'), 'Bill Shakespeare');
equals(library.first().get('length'), 123);
});

test("collection update", function() {
library.first().save({id: '1-the-tempest', author: 'William Shakespeare'});
equals(library.first().get('id'), '1-the-tempest');
equals(library.first().get('title'), 'The Tempest');
equals(library.first().get('author'), 'William Shakespeare');
equals(library.first().get('length'), 123);
});

test("collection destroy", function() {
library.first().destroy();
equals(library.length, 0);
});
equals(library.first().get('id'), '1-the-tempest', 'verify ID update');
equals(library.first().get('title'), 'The Tempest', 'verify title is still there');
equals(library.first().get('author'), 'William Shakespeare', 'verify author update');
equals(library.first().get('length'), 123, 'verify length is still there');
library.each(function(book) {
book.destroy();
});
equals(library.length, 0, 'item was destroyed and library is empty');
});

/*
Expand Down

0 comments on commit 7ad57d7

Please sign in to comment.