Sha256: d09c7c6f00239def6bff9e06166531f272c93c8c1454dcdc64a8d9556dcc333e

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

describe 'The Presenter Mixin', ->
  presenterModel = Luca.register("Luca.models.PresenterModel").extends("Luca.Model")
  presenterModel.mixesIn("ModelPresenter")
  presenterModel.defines
    randomProperty: "chocolate" 
    fullName: ()->
      @get("first_name") + ' ' + @get("last_name")
    defaults: 
      first_name: "Jonathan"
      last_name: "Soeder"

  it "should respond to presentAs", ->
    expect( Luca.models.PresenterModel::presentAs ).toBeDefined()

  it "should define the presenter class methods on the model class", ->
    expect( Luca.models.PresenterModel.registerPresenter ).toBeDefined()

  it "should define the presenter class methods on the model class", ->
    expect( Luca.models.PresenterModel.getPresenter ).toBeDefined()

  it "should register a presenter format", ->
    Luca.models.PresenterModel.registerPresenter "names", ["first_name", "last_name", "fullName"]
    expect( Luca.models.PresenterModel.getPresenter("names") ).toBeDefined()

  it "should present a model in the desired format", ->
    model = new Luca.models.PresenterModel()
    presented = model.presentAs('names')
    expect( _.isObject(presented) ).toEqual true
    expect( presented ).toBeDefined()
    expect( _( presented ).keys()... ).toEqual "first_name", "last_name", "fullName"
    expect( presented.fullName ).toEqual 'Jonathan Soeder'

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
luca-0.9.91 spec/javascripts/concerns/model_presenter_spec.coffee
luca-0.9.9 spec/javascripts/concerns/model_presenter_spec.coffee
luca-0.9.899 spec/javascripts/concerns/model_presenter_spec.coffee
luca-0.9.89 spec/javascripts/concerns/model_presenter_spec.coffee
luca-0.9.8 spec/concerns/model_presenter_spec.coffee
luca-0.9.76 spec/concerns/model_presenter_spec.coffee
luca-0.9.7 spec/concerns/model_presenter_spec.coffee