var test = require('tape')
var supermodels = require('../')

test('scalar array', function (t) {
  var schema = {
    str: String,
    ref: Object,
    aref: [Object]
  }
  var eventCount = 0
  var Model = supermodels(schema)
  var a = new Model({str: 'a'})
  var b = new Model({str: 'b'})
  var c = new Model({str: 'c'})

  // attach 1st handler
  a.on('change', function () {
    ++eventCount
  })

  a.ref = b
  a.aref.push(c)
  b.str = 'bb'
  c.str = 'cc'

  t.equal(eventCount, 4)
  t.equal(b.__parent.str, 'a')
  t.equal(c.__parent.__parent.str, 'a')

  t.end()
})
