Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1346 from elucid/array-proxy-observers

adding failing test for ArrayProxy observer invocation
  • Loading branch information...
commit c6f1f5782830a25f02ee72bbbbd4ea5645f8a594 2 parents b1c0b4c + 66edb81
Peter Wagenet wagenet authored
10 packages/ember-runtime/lib/mixins/sortable.js
View
@@ -37,16 +37,6 @@ Ember.SortableMixin = Ember.Mixin.create(Ember.MutableEnumerable, {
sortProperties: null,
sortAscending: true,
- addObject: function(obj) {
- var content = get(this, 'content');
- content.pushObject(obj);
- },
-
- removeObject: function(obj) {
- var content = get(this, 'content');
- content.removeObject(obj);
- },
-
orderBy: function(item1, item2) {
var result = 0,
sortProperties = get(this, 'sortProperties'),
2  packages/ember-runtime/lib/system/array_proxy.js
View
@@ -94,7 +94,7 @@ Ember.ArrayProxy = Ember.Object.extend(Ember.MutableArray,
@return {void}
*/
replaceContent: function(idx, amt, objects) {
- get(this, 'arrangedContent').replace(idx, amt, objects);
+ get(this, 'content').replace(idx, amt, objects);
},
/**
27 packages/ember-runtime/tests/mixins/sortable_test.js
View
@@ -119,6 +119,20 @@ test("you can add objects in sorted order", function() {
equal(sortedArrayController.objectAt(3).name, 'Scumbag Fucs', 'a new object added to controller was inserted according to given constraint');
});
+test("you can push objects in sorted order", function() {
+ equal(sortedArrayController.get('length'), 3, 'array has 3 items');
+
+ unsortedArray.pushObject({id: 4, name: 'Scumbag Chavard'});
+
+ equal(sortedArrayController.get('length'), 4, 'array has 4 items');
+ equal(sortedArrayController.objectAt(1).name, 'Scumbag Chavard', 'a new object added to content was inserted according to given constraint');
+
+ sortedArrayController.pushObject({id: 5, name: 'Scumbag Fucs'});
+
+ equal(sortedArrayController.get('length'), 5, 'array has 5 items');
+ equal(sortedArrayController.objectAt(3).name, 'Scumbag Fucs', 'a new object added to controller was inserted according to given constraint');
+});
+
test("you can unshift objects in sorted order", function() {
equal(sortedArrayController.get('length'), 3, 'array has 3 items');
@@ -133,6 +147,19 @@ test("you can unshift objects in sorted order", function() {
equal(sortedArrayController.objectAt(3).name, 'Scumbag Fucs', 'a new object added to controller was inserted according to given constraint');
});
+test("addObject does not insert duplicates", function() {
+ var sortedArrayProxy, obj = {};
+ sortedArrayProxy = Ember.ArrayProxy.create(Ember.SortableMixin, {
+ content: Ember.A([obj])
+ });
+
+ equal(sortedArrayProxy.get('length'), 1, 'array has 1 item');
+
+ sortedArrayProxy.addObject(obj);
+
+ equal(sortedArrayProxy.get('length'), 1, 'array still has 1 item');
+});
+
test("you can change a sort property and the content will rearrenge", function() {
equal(sortedArrayController.get('length'), 3, 'array has 3 items');
equal(sortedArrayController.objectAt(0).name, 'Scumbag Bryn', 'bryn is first');
31 packages/ember-runtime/tests/system/array_proxy/content_update_test.js
View
@@ -0,0 +1,31 @@
+// ==========================================================================
+// Project: Ember Runtime
+// Copyright: ©2011 Strobe Inc. and contributors.
+// License: Licensed under MIT license (see license.js)
+// ==========================================================================
+
+module("Ember.ArrayProxy - content update");
+
+test("The `contentArrayDidChange` method is invoked after `content` is updated.", function() {
+
+ var proxy, observerCalled = false;
+
+ proxy = Ember.ArrayProxy.create({
+ content: Ember.A([]),
+
+ arrangedContent: Ember.computed('content', function(key, value) {
+ // setup arrangedContent as a different object than content,
+ // which is the default
+ return Ember.A(this.get('content').slice());
+ }).cacheable(),
+
+ contentArrayDidChange: function(array, idx, removedCount, addedCount) {
+ observerCalled = true;
+ return this._super(array, idx, removedCount, addedCount);
+ }
+ });
+
+ proxy.pushObject(1);
+
+ ok(observerCalled, "contentArrayDidChange is invoked");
+});
Please sign in to comment.
Something went wrong with that request. Please try again.