 
 asyncTest 'it should update the whole set of nodes if the collection changes', ->
   source = '<p data-foreach-object="objects" class="present" data-bind="object"></p>'
-  context = new Batman.Object
-    objects: new Batman.Set('foo', 'bar', 'baz')
+  context = {objects: new Batman.Set('foo', 'bar', 'baz')}
+
   Batman.developer.suppress()
   helpers.render source, false, context, (node, view) ->
     equal $('.present', node).length, 3
-    context.set('objects', new Batman.Set('qux', 'corge'))
+    view.set('objects', new Batman.Set('qux', 'corge'))
     delay =>
       equal $('.present', node).length, 2
-      context.set('objects', null)
+      view.set('objects', null)
       delay =>
         equal $('.present', node).length, 0
-        context.set('objects', new Batman.Set('mario'))
+        view.set('objects', new Batman.Set('mario'))
         delay 60, =>
           equal $('.present', node).length, 1
           Batman.developer.unsuppress()
 
 asyncTest 'it should not fail if the collection is cleared', ->
   source = '<p data-foreach-object="objects" class="present" data-bind="object"></p>'
-  context = new Batman.Object
-    objects: new Batman.Set('foo', 'bar', 'baz')
+  context = {objects: new Batman.Set('foo', 'bar', 'baz')}
 
   helpers.render source, false, context, (node, view) ->
     equal $('.present', node).length, 3
-    context.get('objects').clear()
+    view.get('objects').clear()
     delay =>
       equal $('.present', node).length, 0
 
 asyncTest 'it should not fail if the iterator is killed', 1, ->
   source = '<p data-foreach-object="objects" class="present" data-bind="object"></p>'
-  context = new Batman.Object
-    objects: new Batman.Set([0...100]...)
+  context = {objects: new Batman.Set([0...100]...)}
 
   oldIterator = Batman.DOM.IteratorBinding
   instance = false


asyncTest 'it should update as a hash has items added and removed', 8, ->
  source = '<div><p data-foreach-player="playerScores" data-bind-id="player" data-bind="playerScores[player]"></p></div>'
  context = new Batman.Object
    playerScores: new Batman.Hash
      mario: 5

  helpers.render source, context, (node, view) ->
    equal $(':first', node).attr('id'), 'mario'
    equal $(':first', node).html(), '5'
    context.playerScores.set 'link', 10
    delay =>
      equal $(':first', node).attr('id'), 'mario'
      equal $(':first', node).html(), '5'
      equal $(':nth-child(2)', node).attr('id'), 'link'
      equal $(':nth-child(2)', node).html(), '10'
      context.playerScores.unset 'mario'
      delay =>
        equal $(':first', node).attr('id'), 'link'
        equal $(':first', node).html(), '10'

asyncTest 'it should atomically reorder DOM nodes when the set is reordered', ->
  source = '<div><p data-foreach-object="objects.sortedBy[currentSort]" class="present" data-bind="object.name"></p></div>'
  objects = new Batman.Set({id: 1, name: 'foo'}, {id: 2, name: 'bar'})
  context = {objects, currentSort: 'id'}

  helpers.render source, context, (node, view) ->
    deepEqual getPs(view), ['foo', 'bar']
    # multiple reordering all at once should not end up with duplicate DOM nodes
    view.set('currentSort', 'name')
    delay =>
      view.set('currentSort', 'id')
      delay =>
        view.set('currentSort', 'name')
        delay =>
          deepEqual getPs(view), ['bar', 'foo']

