Skip to content

Instantly share code, notes, and snippets.

@bill-transue
Created May 9, 2012 19:39
Show Gist options
  • Select an option

  • Save bill-transue/2648262 to your computer and use it in GitHub Desktop.

Select an option

Save bill-transue/2648262 to your computer and use it in GitHub Desktop.
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: ''
class Strands.Collections.Sites extends Backbone.Collection
url: '/sites.json'
model: Strands.Models.Site
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