Permalink
Browse files

Fixed MutableArray#unshiftObjects

  • Loading branch information...
wagenet committed May 3, 2012
1 parent 09d7ad6 commit fb0848b2d22e7325f59f89507cd4e855bdad9255
@@ -218,9 +218,7 @@ Ember.MutableArray = Ember.Mixin.create(Ember.Array, Ember.MutableEnumerable,
@returns {Ember.Array} receiver
*/
unshiftObjects: function(objects) {
this.beginPropertyChanges();
forEach(objects, function(obj) { this.unshiftObject(obj); }, this);
this.endPropertyChanges();
this.replace(0, 0, objects);
return this;
},
@@ -0,0 +1,70 @@
// ==========================================================================
// Project: Ember Runtime
// Copyright: ©2011 Strobe Inc. and contributors.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
require('ember-runtime/~tests/suites/mutable_array');
var suite = Ember.MutableArrayTests;
suite.module('unshiftObjects');
suite.test("returns receiver", function() {
var obj = this.newObject([]);
var items = this.newFixture(3);
equal(obj.unshiftObjects(items), obj, 'should return receiver');
});
suite.test("[].unshiftObjects([A,B,C]) => [A,B,C] + notify", function() {
var obj, before, items, observer;
before = [];
items = this.newFixture(3);
obj = this.newObject(before);
observer = this.newObserver(obj, '@each', 'length');
obj.unshiftObjects(items);
deepEqual(this.toArray(obj), items, 'post item results');
equal(Ember.get(obj, 'length'), items.length, 'length');
equal(observer.timesCalled('@each'), 1, 'should have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
});
suite.test("[A,B,C].unshiftObjects([X,Y]) => [X,Y,A,B,C] + notify", function() {
var obj, before, items, after, observer;
before = this.newFixture(3);
items = this.newFixture(2);
after = items.concat(before);
obj = this.newObject(before);
observer = this.newObserver(obj, '@each', 'length');
obj.unshiftObjects(items);
deepEqual(this.toArray(obj), after, 'post item results');
equal(Ember.get(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('@each'), 1, 'should have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
});
suite.test("[A,B,C].unshiftObjects([A,B]) => [A,B,A,B,C] + notify", function() {
var obj, before, after, items, observer;
before = this.newFixture(3);
items = [before[0], before[1]]; // note same object as current head. should end up twice
after = items.concat(before);
obj = this.newObject(before);
observer = this.newObserver(obj, '@each', 'length');
obj.unshiftObjects(items);
deepEqual(this.toArray(obj), after, 'post item results');
equal(Ember.get(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('@each'), 1, 'should have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
});

0 comments on commit fb0848b

Please sign in to comment.