Sha256: df5f9c15d39288374b02a3f4ec735f0842a79e92688e5ff536f596c03a8ec369

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

describe "Lanes.Models.Collection", ->


    it "it triggers promise on loading", (done) ->
        Model = Lanes.Test.defineModel
            props: { id: 'integer', title: 'string' }

        LT.syncSucceedWith([
            { id: 1, title: 'first value'  }
            { id: 2, title: 'second value' }
        ])
        collection = Model.where(name: 'foo')
        expect(collection.requestInProgress).toBeDefined()
        collection.whenLoaded ->
            expect( collection.isLoaded() ).toBe(true)
            done()

    it "triggers length when changed", ->
        Model = Lanes.Test.defineModel
            props: { id: 'integer', title: 'string' }

        collection = new Model.Collection
        spy = jasmine.createSpy('onLengthChange')
        collection.on("change:length", spy)
        model = collection.add({ id: 1, title: 'first' })
        expect(spy).toHaveBeenCalled()
        spy.calls.reset()
        collection.remove(model)
        expect(spy).toHaveBeenCalled()
        spy.calls.reset()
        collection.reset([{ id:11, title: 'last'}])
        expect(spy).toHaveBeenCalled()

    it 'prevents duplicates when copying from', ->
        Model = Lanes.Test.defineModel
            props: { id: 'integer', title: 'string' }
        collection = new Model.Collection
        a = collection.add({ id: 1, title: 'first'  })
        b = collection.add({ id: 2, title: 'second' })
        c = collection.add({ id: 3, title: 'third'  })
        a.copyFrom(c)
        expect(collection.pluck('id')).toEqual([2, 3, 1])

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lanes-0.3.0 spec/lanes/models/CollectionSpec.coffee