Sha256: 950f7a184fa8a482812418cd54da6799094d09c73adccacd2fff44ee0e270552

Contents?: true

Size: 1.69 KB

Versions: 5

Compression:

Stored size: 1.69 KB

Contents

describe "Lanes.Models.AssociationMap", ->
    class Color
        constructor: -> super
        api_path: -> 'test'
        props: { id: 'integer', model_fk_id: 'integer', rgb: 'string' }
    Lanes.Models.Base.extend(Color)

    DATA = {total:1,success:true,message:"Retrieve succeeded",data:[
        [1,"TEST","Nathan Stitt",null,"0.0"]
    ]}
    RESPONSE = {
        status:200,
        contentType: "application/json"
        responseText: JSON.stringify(DATA)
    }
    beforeEach ->
        jasmine.Ajax.install()
    afterEach ->
        jasmine.Ajax.uninstall()

    it "sets up has_many associations", ->
        model = Lanes.Test.makeModel({
            associations:
                color:{ model: Color }
                colors: { collection: Color, fk: 'model_fk_id' }
            props: { id: 'integer', foo: 'string' }
        },{ id: 123 })
        color = model.colors.add({ rgb:'#ffffff' })
        expect(color).toEqual(jasmine.any(Color))
        expect(color.model_fk_id).toEqual(123)

        spy = jasmine.createSpy('sync')
        model.colors.sync = spy

        model.colors.fetch(force:true)

        expect(spy).toHaveBeenCalledWith('read', model.colors, jasmine.any(Object))
        call_options = spy.calls.mostRecent().args[2]
        expect(call_options.query).toEqual( model_fk_id: 123 )


    it "sets up belongs_to associations", ->
        model = Lanes.Test.makeModel({
            associations:
                color:{ model: Color }
            props: { id: 'integer', foo: 'string', color_id: 'integer' }
        },{ id: 123, color: { rgb: 'red' } })
        color = model.color
        expect(model.color).toEqual(jasmine.any(Color))

        expect(model.color.rgb).toEqual('red')

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lanes-0.1.9 spec/lanes/models/AssociationMapSpec.coffee
lanes-0.1.8 spec/lanes/models/ModelAssociationsSpec.coffee
lanes-0.1.7 spec/lanes/models/ModelAssociationsSpec.coffee
lanes-0.1.6 spec/lanes/models/ModelAssociationsSpec.coffee
lanes-0.1.5 spec/lanes/models/ModelAssociationsSpec.coffee