Created
May 9, 2012 19:39
-
-
Save bill-transue/2648262 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Strands.Models.Site extends Backbone.Model | |
| url: -> | |
| if this.isNew() | |
| '/sites.json' | |
| else | |
| '/sites/' + this.id + '.json' | |
| link: -> '/sites/' + this.id | |
| name: -> @get('name') | |
| defaults: | |
| name: '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Strands.Collections.Sites extends Backbone.Collection | |
| url: '/sites.json' | |
| model: Strands.Models.Site |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe 'Strands.Collections.Sites', -> | |
| it 'should be defined', -> | |
| expect(Strands.Collections.Sites).toBeDefined() | |
| it 'can be instantiated', -> | |
| sites = new Strands.Collections.Sites() | |
| expect(sites).not.toBeNull() | |
| beforeEach -> | |
| @sites = new Strands.Collections.Sites() | |
| describe '#fetch', -> | |
| beforeEach -> | |
| @server = sinon.fakeServer.create() | |
| afterEach -> | |
| @server.restore() | |
| describe 'request', -> | |
| beforeEach -> | |
| @sites.fetch() | |
| @request = @server.requests[0] | |
| it 'should be GET', -> | |
| expect(@request).toBeGET() | |
| it 'should be async', -> | |
| expect(@request).toBeAsync() | |
| it 'should have valid url', -> | |
| expect(@request).toHaveUrl '/sites.json' | |
| describe 'on success', -> | |
| beforeEach -> | |
| fixtures = [ | |
| id: 11 | |
| name: 'Severn' | |
| , | |
| id: 12 | |
| name: 'Pasadena' | |
| ] | |
| @server.respondWith "GET", "/sites.json", [ 200, | |
| "Content-Type": "application/json", | |
| JSON.stringify(fixtures) ] | |
| @sites.fetch() | |
| @server.respond() | |
| it 'loaded sites collection', -> | |
| expect(@sites.models.length).toEqual 2 | |
| it 'parses sites from the response', -> | |
| expect(@sites.get(11).get('name')).toEqual 'Severn' | |
| expect(@sites.get(12).get('name')).toEqual 'Pasadena' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment