From ba3d5ffedd04f964a0824bfb20dc5ba6034139ce Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Mon, 18 Jan 2016 16:24:39 -0600 Subject: [PATCH] adds a failing test for 12475 This adds a failing test for #12475. It appears that `obj.set('array', [a1, a2, a3])` fails to install contentKey observers on the new array value so that the subsequent changes to `foo` are ignored. --- .../computed/reduce_computed_macros_test.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/ember-runtime/tests/computed/reduce_computed_macros_test.js b/packages/ember-runtime/tests/computed/reduce_computed_macros_test.js index b037f308862..b36276540d8 100644 --- a/packages/ember-runtime/tests/computed/reduce_computed_macros_test.js +++ b/packages/ember-runtime/tests/computed/reduce_computed_macros_test.js @@ -6,6 +6,7 @@ import { get } from 'ember-metal/property_get'; import { set } from 'ember-metal/property_set'; import { addObserver } from 'ember-metal/observer'; import { observer } from 'ember-metal/mixin'; +import { computed } from 'ember-metal/computed'; import { sum, min, @@ -427,6 +428,28 @@ QUnit.test('properties values can be replaced', function() { deepEqual(obj.get('a1bs').mapBy('name'), ['item1'], 'properties can be filtered by matching value'); }); +QUnit.test('responds to change of property value on element after replacing array', function() { + let a1 = { foo: true, id: 1 }; + let a2 = { foo: true, id: 2 }; + let a3 = { foo: true, id: 4 }; + + obj = EmberObject.extend({ + a: computed('array.@each.foo', function() { + return this.get('array').filter(elt => elt.foo).reduce(((a,b) => a + b.id), 0); + }) + }).create({ + array: emberA([a1, a2]) + }); + + deepEqual(obj.get('a'), 3, 'value is correct initially'); + set(a1, 'foo', false); + deepEqual(obj.get('a'), 2, 'responds to change of property on element'); + obj.set('array', [a1, a2, a3]); + deepEqual(obj.get('a'), 6, 'responds to content array change'); + set(a1, 'foo', true); + deepEqual(obj.get('a'), 7, 'still responds to change of property on element'); +}); + [ ['uniq', uniq], ['union', union]