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 8, 2015
1 parent 9e14bc1 commit 131fe2b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ var hasMany = DS.hasMany;
var belongsTo = DS.belongsTo;
var hash = Ember.RSVP.hash;

// Before https://github.com/emberjs/ember.js/pull/10323 the computed
// property descriptor was stored on the ember meta object. After that
// pr it was moved to the ember object. This code normalized that
// lookup because the Ember Data ci tests run against diferent version
// of Ember. Once that code reaches the release branch this code can
// be removed.
function getComputedPropertyDesc(model, key) {
if (Ember.meta(model).descs) {
return Ember.meta(model).descs[key];
}
var possibleDesc = model[key];
var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;
return desc;
}

module("integration/relationship/belongs_to Belongs-To Relationships", {
setup: function() {
User = DS.Model.extend({
Expand Down Expand Up @@ -362,15 +377,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 +395,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 +413,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 Expand Up @@ -451,7 +469,7 @@ test("relationship changes shouldn’t cause async fetches", function() {
env.adapter.deleteRecord = function(store, type, record) {
ok(record instanceof type);
equal(record.id, 1, 'should first comment');
return record;
return record.toJSON({ includeId: true });
};

env.adapter.findMany = function(store, type, ids, records) {
Expand Down Expand Up @@ -492,7 +510,12 @@ test("Destroying a record with an unloaded aync belongsTo association does not f
env.adapter.deleteRecord = function(store, type, record) {
ok(record instanceof type);
equal(record.id, 1, 'should first post');
return record;
return {
id: "1",
title: null,
created_at: null,
user: "2"
};
};

run(post, 'destroyRecord');
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
9 changes: 7 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,11 @@ 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 emptyLength = Ember.meta(store).descs ? undefined : 0;

var recordArray = store.all(Person);
run(function() {
store.push(Person, { id: 1, name: 'wycats' });
Expand All @@ -59,11 +64,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 131fe2b

Please sign in to comment.