Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Fix development build relationship caching. #5332

Merged
merged 1 commit into from
Jan 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions addon/-private/system/relationships/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ import { A } from '@ember/array';
import { computed } from '@ember/object';
import MapWithDefault from '@ember/map/with-default';
import Map from '@ember/map';
import Ember from 'ember';
import { assert } from '@ember/debug';
import {
typeForRelationshipMeta,
relationshipFromMeta
} from "../relationship-meta";

export const relationshipsDescriptor = computed(function() {
if (Ember.testing === true && relationshipsDescriptor._cacheable === true) {
relationshipsDescriptor._cacheable = false;
}

let map = new MapWithDefault({
defaultValue() { return []; }
});
Expand All @@ -37,10 +32,6 @@ export const relationshipsDescriptor = computed(function() {
}).readOnly();

export const relatedTypesDescriptor = computed(function() {
if (Ember.testing === true && relatedTypesDescriptor._cacheable === true) {
relatedTypesDescriptor._cacheable = false;
}

let modelName;
let types = A();

Expand Down
73 changes: 0 additions & 73 deletions tests/integration/relationships/belongs-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { get } from '@ember/object';
import { run } from '@ember/runloop';
import RSVP, { resolve } from 'rsvp';
import setupStore from 'dummy/tests/helpers/store';
import Ember from 'ember';

import testInDebug from 'dummy/tests/helpers/test-in-debug';
import {
Expand Down Expand Up @@ -542,78 +541,6 @@ test("relationshipsByName does not cache a factory", function(assert) {
"model factory based on relationship type matches the model based on store.modelFor");
});

function getDescriptor(object, key) {
var meta = Ember.meta(object);
var mixins = (meta && meta._mixins) || {};
for (let key in mixins) {
let klass = mixins[key]
if (!klass.properties) {
continue;
}
let descriptor = klass.properties[key];
if (descriptor) {
return descriptor;
}
}
// Fallback to grabbing the descriptor off of the object for old
// versions of Ember
return object[key];
}

test("relationshipsByName is cached in production", function(assert) {
let model = store.modelFor('user');
let 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
let relationshipsByName = getDescriptor(model, 'relationshipsByName');
let oldCacheable = relationshipsByName._cacheable;
relationshipsByName._cacheable = true;
Ember.testing = false;
try {
assert.equal(get(model, 'relationshipsByName'), get(model, 'relationshipsByName'), 'relationshipsByName are cached');
assert.equal(get(model, 'relationshipsByName'), get(model, 'relationshipsByName'), 'relationshipsByName are cached');
} finally {
Ember.testing = oldTesting;
relationshipsByName._cacheable = oldCacheable;
}
});

test("relatedTypes is cached in production", function(assert) {
let model = store.modelFor('user');
let 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
let relatedTypes = getDescriptor(model, 'relatedTypes');
let oldCacheable = relatedTypes._cacheable;
relatedTypes._cacheable = true;
Ember.testing = false;
try {
assert.equal(get(model, 'relatedTypes'), get(model, 'relatedTypes'), 'relatedTypes are cached');
assert.equal(get(model, 'relatedTypes'), get(model, 'relatedTypes'), 'relatedTypes are cached');
} finally {
Ember.testing = oldTesting;
relatedTypes._cacheable = oldCacheable;
}
});

test("relationships is cached in production", function(assert) {
let model = store.modelFor('user');
let 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
let relationships = getDescriptor(model, 'relationships');
let oldCacheable = relationships._cacheable;
relationships._cacheable = true;
Ember.testing = false;
try {
assert.equal(get(model, 'relationships'), get(model, 'relationships'), 'relationships are cached');
assert.equal(get(model, 'relationships'), get(model, 'relationships'), 'relationships are cached');
} finally {
Ember.testing = oldTesting;
relationships._cacheable = oldCacheable;
}
});

test("relationship changes shouldn’t cause async fetches", function(assert) {
assert.expect(2);

Expand Down