Sha256: 64d13d58930de849f367d0afde07c00de70a0e45cf5226b831d35e13a9fb003d

Contents?: true

Size: 1.76 KB

Versions: 11

Compression:

Stored size: 1.76 KB

Contents

#### Luca.Model
describe "Luca.Model with computed attribute", ->
  App =
    models: {}

  App.models.Sample = Luca.Model.extend
    computed:
      fullName: ['firstName', 'lastName']

    fullName: ()->
      "#{@get("firstName")} #{@get("lastName")}"

  App.models.SampleWithoutCallback = Luca.Model.extend
    computed:
      fullName: ['firstName', 'lastName']

  it "should have it undefined if dependences are not set", ->
    model = new App.models.Sample
    expect(model.get("fullName")).toEqual(undefined)

  it "should have it undefined if callback function is not present", ->
    model = new App.models.SampleWithoutCallback
    expect(model.get("fullName")).toEqual(undefined)

  it "should not call it's callback if dependences are not set", ->
    model = new App.models.Sample
    spy   = sinon.spy(model, "fullName")
    expect( spy.called ).toEqual(false)

  it "should not call it's callback if dependencies stay the same", ->
    model = new App.models.Sample
    model.set({firstName:"Nickolay", lastName: "Schwarz"})
    spy   = sinon.spy(model, "fullName")
    model.set({lastName: "Schwarz"})
    expect( spy.called ).toEqual(false)

  it "should call it's callback when dependencies change", ->
    model = new App.models.Sample
    spy   = sinon.spy(model, "fullName")
    model.set({firstName:"Nickolay"})
    expect( spy.called ).toEqual(true)

  it "should be gettable as a value of the callback", ->
    model = new App.models.Sample
    model.set({firstName:"Nickolay", lastName: "Schwarz"})
    expect(model.get("fullName")).toEqual(model.fullName())

  it "should have it set on constructor if dependencies are supplied", ->
    model = new App.models.Sample({firstName:"Nickolay", lastName: "Schwarz"})
    expect(model.get("fullName")).toEqual('Nickolay Schwarz')

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
luca-0.9.42 spec/core/model_spec.coffee
luca-0.9.4 spec/core/model_spec.coffee
luca-0.9.2 spec/core/model_spec.coffee
luca-0.9.1 spec/core/model_spec.coffee
luca-0.9.0 spec/core/model_spec.coffee
luca-0.8.599 spec/core/model_spec.coffee
luca-0.8.59 spec/core/model_spec.coffee
luca-0.8.3 spec/core/model_spec.coffee
luca-0.8.2 spec/core/model_spec.coffee
luca-0.8.06 spec/core/model_spec.coffee
luca-0.8 spec/core/model_spec.coffee