Skip to content

Commit

Permalink
Various amendments
Browse files Browse the repository at this point in the history
  • Loading branch information
froots committed Mar 23, 2011
1 parent 5425c0b commit cee8117
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions public/javascripts/collections/Todos.js
@@ -1,6 +1,7 @@
var Todos = Backbone.Collection.extend({

url: '/todos',
model: Todo,

parse: function(response) {
var todos = response.response.todos;
Expand Down
8 changes: 4 additions & 4 deletions spec/javascripts/collections/Todos.spec.js
Expand Up @@ -34,21 +34,21 @@ describe("Todos collection", function() {
describe("When instantiated with model literal", function() {

beforeEach(function() {
this.model = new Backbone.Model({id: 5, title: 'Foo'})
this.model = new Backbone.Model({id: 5, title: "Foo"});
this.todoStub.returns(this.model);
this.todos.add(this.model);
this.todos.add({id:5, title:"Foo"});
});

it("should have 1 Todo model", function() {
expect(this.todos.length).toEqual(1);
});

it("should find a model by id", function() {
expect(this.todos.get(5)).toEqual(this.model);
expect(this.todos.get(5).get("id")).toEqual(this.model.get("id"));
});

it("should find a model by index", function() {
expect(this.todos.at(0)).toEqual(this.model);
expect(this.todos.at(0).get("id")).toEqual(this.model.get("id"));
});

});
Expand Down
10 changes: 6 additions & 4 deletions spec/javascripts/models/Todo.spec.js
Expand Up @@ -5,8 +5,10 @@ describe("Todo model", function() {
title: "Rake leaves",
tags: ["garden", "weekend"]
});
this.Col = Backbone.Collection.extend({url: "/collection"});
this.collection = new this.Col([this.todo]);
var collection = {
url: "/collection"
};
this.todo.collection = collection;
});

describe("when instantiated", function() {
Expand Down Expand Up @@ -62,12 +64,12 @@ describe("Todo model", function() {
this.server.restore();
});

it("should not save when title is undefined", function() {
it("should not save when title is empty", function() {
this.todo.bind("error", this.eventSpy);
this.todo.save({"title": ""});

expect(this.eventSpy).toHaveBeenCalledOnce();
expect(this.eventSpy).toHaveBeenCalledWith(this.todo, "cannot have an empty title");
expect(this.server.requests.length).toEqual(0);
});

it("should make a save request to the server", function() {
Expand Down
3 changes: 2 additions & 1 deletion spec/javascripts/support/jasmine.yml
Expand Up @@ -17,7 +17,8 @@ src_files:
- public/javascripts/lib/jquery-1.5.1.min.js
- public/javascripts/lib/underscore-min.js
- public/javascripts/lib/backbone-min.js
- public/javascripts/**/*.js
- public/javascripts/models/*.js
- public/javascripts/collections/*.js

# stylesheets
#
Expand Down

0 comments on commit cee8117

Please sign in to comment.