require('tape')('model', function (t) {
var Model = require('../model')
var mac   = require('macgyver')().autoValidate()

var a = new Model()

var expected = {
  key: Math.random()
}

a.on('change', mac(function (key, value) {
  t.ok(expected[key] !== undefined)
  t.equal(value, expected[key])
  next()
}).atLeast(1))

a.on('change:key', mac(function (value) {
  t.equal(value, expected.key)
  next()
}).once())

a.set('key', expected.key)

  var n = 2
  function next () {
    if(--n) return
    t.end()
  }

})

@@ -177,20 +177,51 @@
 om()%0A%7D%0A%0A
+t.deepEqual(%7B%7D, a.toJSON())%0A%0A
 a.on
+ce
 ('change
@@ -319,16 +319,52 @@
 d%5Bkey%5D)%0A
+  t.deepEqual(a.toJSON(), expected)%0A
   next()
@@ -384,16 +384,18 @@
 ))%0A%0Aa.on
+ce
 ('change
@@ -480,35 +480,8 @@
 ))%0A%0A
-a.set('key', expected.key)%0A
 %0A  v
@@ -533,24 +533,143 @@
 urn%0A
-    t.end()%0A  %7D
+%0A    a.set('key', null)%0A    t.equal(a.get('key'), null)%0A    t.deepEqual(a.toJSON(), %7B%7D)%0A%0A    t.end()%0A  %7D%0A%0Aa.set('key', expected.key)%0A
 %0A%0A%7D)%0A
+%0A

test Model.toJSON()