Skip to content

Commit

Permalink
Fix tests on canary. They broke when Ember.js removed the meta.descs
Browse files Browse the repository at this point in the history
  • Loading branch information
bmac committed Feb 5, 2015
1 parent 9e14bc1 commit 2a35e00
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 26 deletions.
32 changes: 18 additions & 14 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1786,10 +1786,12 @@ function normalizeRelationships(store, type, data, record) {
type.eachRelationship(function(key, relationship) {
var kind = relationship.kind;
var value = data[key];
if (kind === 'belongsTo') {
deserializeRecordId(store, data, key, relationship, value);
} else if (kind === 'hasMany') {
deserializeRecordIds(store, data, key, relationship, value);
if (!(value instanceof Ember.ComputedProperty)) {
if (kind === 'belongsTo') {
deserializeRecordId(store, data, key, relationship, value);
} else if (kind === 'hasMany') {
deserializeRecordIds(store, data, key, relationship, value);
}
}
});

Expand Down Expand Up @@ -2072,19 +2074,21 @@ function setupRelationships(store, record, data) {
type.eachRelationship(function(key, descriptor) {
var kind = descriptor.kind;
var value = data[key];
var relationship = record._relationships[key];
if (!(value instanceof Ember.ComputedProperty)) {
var relationship = record._relationships[key];

if (data.links && data.links[key]) {
relationship.updateLink(data.links[key]);
}
if (data.links && data.links[key]) {
relationship.updateLink(data.links[key]);
}

if (kind === 'belongsTo') {
if (value === undefined) {
return;
if (kind === 'belongsTo') {
if (value === undefined) {
return;
}
relationship.setCanonicalRecord(value);
} else if (kind === 'hasMany' && value) {
relationship.updateRecordsFromAdapter(value);
}
relationship.setCanonicalRecord(value);
} else if (kind === 'hasMany' && value) {
relationship.updateRecordsFromAdapter(value);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ var hasMany = DS.hasMany;
var belongsTo = DS.belongsTo;
var hash = Ember.RSVP.hash;

function getComputedPropertyDesc(model, key) {
return Ember.meta(model).descs ? Ember.meta(model).descs[key] : model[key];
}

module("integration/relationship/belongs_to Belongs-To Relationships", {
setup: function() {
User = DS.Model.extend({
Expand Down Expand Up @@ -362,15 +366,16 @@ test("relationshipsByName is cached in production", function() {
var oldTesting = Ember.testing;
//We set the cacheable to true because that is the default state for any CP and then assert that it
//did not get dynamically changed when accessed
var oldCacheable = Ember.meta(model).descs.relationshipsByName._cacheable;
Ember.meta(model).descs.relationshipsByName._cacheable = true;
var relationshipsByName = getComputedPropertyDesc(model, 'relationshipsByName');
var oldCacheable = relationshipsByName._cacheable;
relationshipsByName._cacheable = true;
Ember.testing = false;
try {
equal(get(model, 'relationshipsByName'), get(model, 'relationshipsByName'), 'relationshipsByName are cached');
equal(get(model, 'relationshipsByName'), get(model, 'relationshipsByName'), 'relationshipsByName are cached');
} finally {
Ember.testing = oldTesting;
Ember.meta(model).descs.relationshipsByName._cacheable = oldCacheable;
relationshipsByName._cacheable = oldCacheable;
}
});

Expand All @@ -379,15 +384,16 @@ test("relatedTypes is cached in production", function() {
var oldTesting = Ember.testing;
//We set the cacheable to true because that is the default state for any CP and then assert that it
//did not get dynamically changed when accessed
var oldCacheable = Ember.meta(model).descs.relatedTypes._cacheable;
Ember.meta(model).descs.relatedTypes._cacheable = true;
var relatedTypes = getComputedPropertyDesc(model, 'relatedTypes');
var oldCacheable = relatedTypes._cacheable;
relatedTypes._cacheable = true;
Ember.testing = false;
try {
equal(get(model, 'relatedTypes'), get(model, 'relatedTypes'), 'relatedTypes are cached');
equal(get(model, 'relatedTypes'), get(model, 'relatedTypes'), 'relatedTypes are cached');
} finally {
Ember.testing = oldTesting;
Ember.meta(model).descs.relatedTypes._cacheable = oldCacheable;
relatedTypes._cacheable = oldCacheable;
}
});

Expand All @@ -396,15 +402,16 @@ test("relationships is cached in production", function() {
var oldTesting = Ember.testing;
//We set the cacheable to true because that is the default state for any CP and then assert that it
//did not get dynamically changed when accessed
var oldCacheable = Ember.meta(model).descs.relatedTypes._cacheable;
Ember.meta(model).descs.relationships._cacheable = true;
var relationships = getComputedPropertyDesc(model, 'relationships');
var oldCacheable = relationships._cacheable;
relationships._cacheable = true;
Ember.testing = false;
try {
equal(get(model, 'relationships'), get(model, 'relationships'), 'relationships are cached');
equal(get(model, 'relationships'), get(model, 'relationships'), 'relationships are cached');
} finally {
Ember.testing = oldTesting;
Ember.meta(model).descs.relationships._cacheable = oldCacheable;
relationships._cacheable = oldCacheable;
}
});

Expand Down
1 change: 0 additions & 1 deletion packages/ember-data/tests/integration/store_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ test("destroying the store correctly cleans everything up", function() {
Ember.run(store, 'destroy');

equal(car.get('person'), null, "expected car.person to no longer be present");
equal(person.get('cars'), undefined, "expected person.cars to be empty");

equal(personWillDestroy.called.length, 1, 'expected person to have recieved willDestroy once');
equal(carWillDestroy.called.length, 1, 'expected car to recieve willDestroy once');
Expand Down
13 changes: 11 additions & 2 deletions packages/ember-data/tests/unit/record_array_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ test("stops updating when destroyed", function() {
expect(3);
var store = createStore();

// TODO remove once
// https://github.com/emberjs/ember.js/commit/c3f13e85a62069295965dd49ca487fe6ddba1188
// is on the release branch
var arrayProxy = Ember.ArrayProxy.create();
run(function() {
arrayProxy.destroy();
});
var emptyLength = arrayProxy.get('length');

var recordArray = store.all(Person);
run(function() {
store.push(Person, { id: 1, name: 'wycats' });
Expand All @@ -59,11 +68,11 @@ test("stops updating when destroyed", function() {
});

run(function() {
equal(recordArray.get('length'), undefined, "Has no more records");
equal(recordArray.get('length'), emptyLength, "Has no more records");
store.push(Person, { id: 2, name: 'brohuda' });
});

equal(recordArray.get('length'), undefined, "Has not been updated");
equal(recordArray.get('length'), emptyLength, "Has not been updated");
equal(recordArray.get('content'), undefined, "Has not been updated");
});

Expand Down

0 comments on commit 2a35e00

Please sign in to comment.