Sha256: 2697334d1b9baededea4afc89d41ac58f2b49e893974d70d7efc28cdb8a95a19

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

describe "Joosy.Resource.RESTCollection", ->

  class Test extends Joosy.Resource.REST
    @entity 'test'

  beforeEach ->
    @server = sinon.fakeServer.create()
    @collection = new Joosy.Resource.RESTCollection(Test)

  afterEach ->
    @server.restore()

  it "loads", ->
    @collection.load [{"id": 1, "name": "test1"}, {"id": 2, "name": "test2"}]
    console.log @collection.data[0].constructor
    expect(@collection.data.length).toEqual 2
    expect(@collection.data[0] instanceof Test).toBeTruthy()
    expect(@collection.data[0].data.name).toEqual 'test1'

  it "reloads", ->
    @collection.load [{"id": 1, "name": "test1"}, {"id": 2, "name": "test2"}]
    @collection.reload from: 'test'

    target = @server.requests.last()
    expect(target.method).toEqual 'GET'
    expect(target.url).toMatch /^\/tests\/test\?_=\d+/
    target.respond 200, 'Content-Type': 'application/json', '[{"id": 3, "name": "test3"}, {"id": 4, "name": "test4"}, {"id": 5, "name": "test5"}]'

    expect(@collection.data.length).toEqual 3
    expect(@collection.data[0].constructor == Test).toBeTruthy()
    expect(@collection.data[0].data.name).toEqual 'test3'

  it "should use own storage", ->
    class TestsCollection extends Joosy.Resource.RESTCollection
      @model Test
    collection = new TestsCollection()
    collection.add 'test'
    expect(collection.data).toEqual ['test']
    expect(collection.hasOwnProperty 'data').toBeTruthy()

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
joosy-1.0.0.RC4 spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee
joosy-1.0.0.RC3 spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee
joosy-1.0.0.RC2 spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee