   equalArray even,[2,4]
 
 test 'forEach up to date when all changes', ->
-  nums.pushObject(8)
+  Ember.run -> nums.pushObject(8)
   equalArray even,[2,4,8]
 
 test 'observer of EvenArray is updated', ->
-  nums.pushObject(8)
-  equal observer.get('arrayDidChangeCount'),1
+  Ember.run -> nums.pushObject(8)
+  Ember.run -> equal observer.get('arrayDidChangeCount'),1
 
 test 'observer of EvenArray is not updated on odd', ->
-  nums.pushObject(9)
+  Ember.run -> nums.pushObject(9)
   equal observer.get('arrayDidChangeCount'),0
 
 test 'filtered array with max size', ->
-  observer = MyObserver.create()
-  nums = Ember.A([1,2,3,4,5])
-  even = FilteredArray.create(all: nums, filterFunc: (num,i) -> i <= 3)
-  even.addArrayObserver(observer)
+  Ember.run -> 
+    observer = MyObserver.create()
+    nums = Ember.A([1,2,3,4,5])
+    even = FilteredArray.create(all: nums, filterFunc: (num,i) -> i <= 3)
+    even.addArrayObserver(observer)
 
   equalArray even,[1,2,3,4]
 
-  nums.pushObject(9)
+  Ember.run -> nums.pushObject(9)
   equalArray even,[1,2,3,4]
 
 test 'filtered array with max size 2', ->
-  observer = MyObserver.create()
-  nums = Ember.A([1,2,3,4,5])
-  even = FilteredArray.create(all: nums, filterFunc: (num,i) -> i <= 5)
-  even.addArrayObserver(observer)
+  Ember.run -> 
+    observer = MyObserver.create()
+    nums = Ember.A([1,2,3,4,5])
+    even = FilteredArray.create(all: nums, filterFunc: (num,i) -> i <= 5)
+    even.addArrayObserver(observer)
 
   equalArray even,[1,2,3,4,5]
 
-  nums.pushObject(6)
+  Ember.run -> nums.pushObject(6)
   equal observer.get('arrayDidChangeCount'),1
 
-  nums.pushObject(7)
+  Ember.run -> nums.pushObject(7)
   equal observer.get('arrayDidChangeCount'),1
 
 test 'observer updates when multiple pushed at once', ->
-  nums.pushObjects([8,10])
+  Ember.run -> nums.pushObjects([8,10])
   equal observer.get('arrayDidChangeCount'),2
 
 
 test 'make FilteredArray on the fly', ->
-  observer = MyObserver.create()
-  nums = Ember.A([1,2,3,4,5])
-  even = FilteredArray.create(all: nums, filterFunc: (num) -> num >= 3)
-
-  even.addArrayObserver(observer)
+  Ember.run -> 
+    observer = MyObserver.create()
+    nums = Ember.A([1,2,3,4,5])
+    even = FilteredArray.create(all: nums, filterFunc: (num) -> num >= 3)
+    even.addArrayObserver(observer)
 
   equalArray even,[3,4,5]
 
-  nums.pushObject(-4)
+  Ember.run -> nums.pushObject(-4)
   equal observer.get('arrayDidChangeCount'),0
 
-  nums.pushObject(8)
+  Ember.run -> nums.pushObject(8)
   equal observer.get('arrayDidChangeCount'),1
   equalArray even,[3,4,5,8]
 

nums = null
even = null

module 'Integration - Pagination', 
  setup: ->
    observer = MyObserver.create()
    nums = Ember.A([1,2,3,4,5])
    even = EvenArray.create(all: nums)
    even.addArrayObserver(observer)

  tearDown: ->
    observer = null


FilteredObserver = Ember.Object.extend
  arrayWillChange: (observedObj, start, removeCount, addCount) ->
    # do nothing

  arrayDidChange: (observedObj, start, removeCount, addCount) ->
    for i in [start...(start+addCount)]
      obj = observedObj[i]
      if @get('parent').filterFunc(obj,i)
        @get('parent').pushObject(obj)


FilteredArray = Ember.Object.extend Ember.MutableArray,
  init: (ops) ->
    @get('all').addArrayObserver(FilteredObserver.create(parent: this))

  "[]": (->
    c = []
    i = 0
    for num in @get('all')
      if @filterFunc(num,i)
        c.push(num)
      i += 1
    Ember.A(c)).property()

  replace: (i,thing,objects) ->
    for obj in objects
      @get('[]').pushObject(obj)
      @arrayContentDidChange(@get('[].length')-1,0,1)

  objectAt: (i) ->
    @get('[]').objectAt(i)

  lengthBinding: "[].length"

EvenArray = FilteredArray.extend
  filterFunc: (num) -> num%2 == 0
