Skip to content

Commit

Permalink
drop use of MODEL_FACTORY_FOR
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Nov 8, 2018
1 parent e644897 commit b044851
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 190 deletions.
5 changes: 1 addition & 4 deletions addon/-debug/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Ember from 'ember';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';

Expand Down Expand Up @@ -34,9 +33,7 @@ if (DEBUG) {
//once it exists in Ember
return modelClass.__mixin.detect(addedModelClass.PrototypeMixin);
}
if (Ember.MODEL_FACTORY_INJECTIONS) {
modelClass = modelClass.superclass;
}

return modelClass.detect(addedModelClass);
};

Expand Down
20 changes: 0 additions & 20 deletions tests/helpers/model-factory-injection.js

This file was deleted.

12 changes: 3 additions & 9 deletions tests/integration/injection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module('integration/injection factoryFor enabled', function(hooks) {
setupTest(hooks);
let store;
let Model;
let factory;

hooks.beforeEach(function() {
let { owner } = this;
Expand All @@ -16,19 +15,14 @@ module('integration/injection factoryFor enabled', function(hooks) {
};
owner.register('model:super-villain', Model);
store = owner.lookup('service:store');

let originalFactoryFor = owner.factoryFor;

owner.factoryFor = function interceptFactoryFor() {
factory = originalFactoryFor.call(owner, ...arguments);
return factory;
};
});

test('modelFactoryFor', function(assert) {
let { owner } = this;
const trueFactory = owner.factoryFor('model:super-villain');
const modelFactory = store._modelFactoryFor('super-villain');

assert.strictEqual(modelFactory, factory, 'expected the factory itself to be returned');
assert.strictEqual(modelFactory, trueFactory, 'expected the factory itself to be returned');
});

test('modelFor', function(assert) {
Expand Down
11 changes: 2 additions & 9 deletions tests/integration/relationships/belongs-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import Store from 'ember-data/store';
import Model from 'ember-data/model';
import { attr, belongsTo } from '@ember-decorators/data';
import testInDebug from 'dummy/tests/helpers/test-in-debug';
import {
setup as setupModelFactoryInjections,
reset as resetModelFactoryInjection,
} from 'dummy/tests/helpers/model-factory-injection';
import DS from 'ember-data';
import {
RecordData,
Expand Down Expand Up @@ -279,7 +275,6 @@ module('integration/relationship/belongs_to Belongs-To Relationships', {
},

afterEach() {
resetModelFactoryInjection();
run(env.container, 'destroy');
},
});
Expand Down Expand Up @@ -827,7 +822,7 @@ test('A record can be created with a resolved belongsTo promise', function(asser
});
});

test('polymorphic belongsTo class-checks check the superclass when MODEL_FACTORY_INJECTIONS is enabled', function(assert) {
test('polymorphic belongsTo class-checks check the superclass', function(assert) {
assert.expect(1);

run(() => {
Expand All @@ -841,7 +836,6 @@ test('polymorphic belongsTo class-checks check the superclass when MODEL_FACTORY
});

test('the subclass in a polymorphic belongsTo relationship is an instanceof its superclass', function(assert) {
setupModelFactoryInjections(false);
assert.expect(1);

let message = env.store.createRecord('message', { id: 1 });
Expand All @@ -858,8 +852,7 @@ test('relationshipsByName does not cache a factory', function(assert) {
// An app is reset, or the container otherwise destroyed.
run(env.container, 'destroy');

// A new model for a relationship is created. Note that this may happen
// due to an extend call internal to MODEL_FACTORY_INJECTIONS.
// A new model for a relationship is created.
NewMessage = Message.extend();

// A new store is created.
Expand Down
28 changes: 9 additions & 19 deletions tests/integration/relationships/has-many-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/*eslint no-unused-vars: ["error", { "args": "none", "varsIgnorePattern": "(page)" }]*/

import {
setup as setupModelFactoryInjections,
reset as resetModelFactoryInjections,
} from 'dummy/tests/helpers/model-factory-injection';
import { A } from '@ember/array';
import { resolve, Promise as EmberPromise, all, reject, hash } from 'rsvp';
import { get } from '@ember/object';
Expand Down Expand Up @@ -1497,25 +1493,19 @@ test("When a polymorphic hasMany relationship is accessed, the store can call mu
});
});

test('polymorphic hasMany type-checks check the superclass when MODEL_FACTORY_INJECTIONS is enabled', function(assert) {
test('polymorphic hasMany type-checks check the superclass', function(assert) {
assert.expect(1);

setupModelFactoryInjections();

try {
run(function() {
let igor = env.store.createRecord('user', { name: 'Igor' });
let comment = env.store.createRecord('comment', {
body: 'Well I thought the title was fine',
});
run(function() {
let igor = env.store.createRecord('user', { name: 'Igor' });
let comment = env.store.createRecord('comment', {
body: 'Well I thought the title was fine',
});

igor.get('messages').addObject(comment);
igor.get('messages').addObject(comment);

assert.equal(igor.get('messages.firstObject.body'), 'Well I thought the title was fine');
});
} finally {
resetModelFactoryInjections();
}
assert.equal(igor.get('messages.firstObject.body'), 'Well I thought the title was fine');
});
});

test('Type can be inferred from the key of a hasMany relationship', function(assert) {
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/relationships/json-api-links-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { run } from '@ember/runloop';
import { get } from '@ember/object';
import { resolve } from 'rsvp';
import setupStore from 'dummy/tests/helpers/store';
import { reset as resetModelFactoryInjection } from 'dummy/tests/helpers/model-factory-injection';
import { module, test } from 'qunit';
import DS from 'ember-data';
import JSONAPIAdapter from 'ember-data/adapters/json-api';
Expand All @@ -16,7 +15,6 @@ module('integration/relationship/json-api-links | Relationship state updates', {
beforeEach() {},

afterEach() {
resetModelFactoryInjection();
run(env.container, 'destroy');
},
});
Expand Down Expand Up @@ -691,7 +689,6 @@ module('integration/relationship/json-api-links | Relationship fetching', {
},

afterEach() {
resetModelFactoryInjection();
run(env.container, 'destroy');
env = null;
},
Expand Down
102 changes: 43 additions & 59 deletions tests/integration/relationships/polymorphic-mixins-belongs-to-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
setup as setupModelFactoryInjections,
reset as resetModelFactoryInjections,
} from 'dummy/tests/helpers/model-factory-injection';

import Mixin from '@ember/object/mixin';
import { run } from '@ember/runloop';
import setupStore from 'dummy/tests/helpers/store';
Expand Down Expand Up @@ -174,9 +169,45 @@ testInDebug(

test('Setting the polymorphic belongsTo gets propagated to the inverse side - model injections true', function(assert) {
assert.expect(2);
setupModelFactoryInjections();

try {
var user, video;
run(function() {
store.push({
data: [
{
type: 'user',
id: '1',
attributes: {
name: 'Stanley',
},
},
{
type: 'video',
id: '2',
attributes: {
video: 'Here comes Youtube',
},
},
],
});
user = store.peekRecord('user', 1);
video = store.peekRecord('video', 2);
});

run(function() {
user.set('bestMessage', video);
video.get('user').then(function(fetchedUser) {
assert.equal(fetchedUser, user, 'user got set correctly');
});
user.get('bestMessage').then(function(message) {
assert.equal(message, video, 'The message was set correctly');
});
});
});

testInDebug(
'Setting the polymorphic belongsTo with an object that does not implement the mixin errors out - model injections true',
function(assert) {
var user, video;
run(function() {
store.push({
Expand All @@ -189,7 +220,7 @@ test('Setting the polymorphic belongsTo gets propagated to the inverse side - mo
},
},
{
type: 'video',
type: 'not-message',
id: '2',
attributes: {
video: 'Here comes Youtube',
Expand All @@ -198,60 +229,13 @@ test('Setting the polymorphic belongsTo gets propagated to the inverse side - mo
],
});
user = store.peekRecord('user', 1);
video = store.peekRecord('video', 2);
video = store.peekRecord('not-message', 2);
});

run(function() {
user.set('bestMessage', video);
video.get('user').then(function(fetchedUser) {
assert.equal(fetchedUser, user, 'user got set correctly');
});
user.get('bestMessage').then(function(message) {
assert.equal(message, video, 'The message was set correctly');
});
assert.expectAssertion(function() {
user.set('bestMessage', video);
}, /The 'not-message' type does not implement 'message' and thus cannot be assigned to the 'bestMessage' relationship in 'user'. Make it a descendant of 'message'/);
});
} finally {
resetModelFactoryInjections();
}
});

testInDebug(
'Setting the polymorphic belongsTo with an object that does not implement the mixin errors out - model injections true',
function(assert) {
setupModelFactoryInjections();

try {
var user, video;
run(function() {
store.push({
data: [
{
type: 'user',
id: '1',
attributes: {
name: 'Stanley',
},
},
{
type: 'not-message',
id: '2',
attributes: {
video: 'Here comes Youtube',
},
},
],
});
user = store.peekRecord('user', 1);
video = store.peekRecord('not-message', 2);
});

run(function() {
assert.expectAssertion(function() {
user.set('bestMessage', video);
}, /The 'not-message' type does not implement 'message' and thus cannot be assigned to the 'bestMessage' relationship in 'user'. Make it a descendant of 'message'/);
});
} finally {
resetModelFactoryInjections();
}
}
);
Loading

0 comments on commit b044851

Please sign in to comment.