Skip to content

Commit 74c6772

Browse files
authored
Merge pull request #116 from jbryson3/feature/pass-model-arguments-to-createRecord
During model transform preserve the argument passed to this.subject
2 parents a89493f + d23d5bc commit 74c6772

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import { setupModelTest } from 'ember-mocha';
4+
5+
describe('Unit | Model | rental', function() {
6+
setupModelTest('rental', {
7+
needs: []
8+
});
9+
// Replace this with your real tests.
10+
it('exists', function() {
11+
let model = this.subject({num: 5, obj: {key: 'val'}, arr: [1,'two']});
12+
expect(model).to.be.ok;
13+
});
14+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import { setupTest } from 'ember-mocha';
4+
5+
describe('Unit | Model | rental', function() {
6+
setupTest();
7+
// Replace this with your real tests.
8+
it('exists', function() {
9+
let model = this.owner.lookup('service:store').createRecord('rental', {num: 5, obj: {key: 'val'}, arr: [1,'two']});
10+
expect(model).to.be.ok;
11+
});
12+
});

fourteen-testing-api.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ module.exports = function(file, api) {
502502
)
503503
);
504504
} else if (subjectType === 'model') {
505+
let createRecordArg = p.node.arguments[0] ?
506+
p.node.arguments[0] : /* the argument provided to this.subject() */
507+
j.objectExpression([]) /* empty object expression {} */;
505508
p.replace(
506509
j.callExpression(
507510
j.memberExpression(
@@ -516,7 +519,7 @@ module.exports = function(file, api) {
516519
),
517520
// creating an empty object expression {} as the 2nd argument here
518521
// because setupModelTests shouldn't need store dependencies
519-
[j.literal(subjectName), j.objectExpression([])].filter(Boolean)
522+
[j.literal(subjectName), createRecordArg].filter(Boolean)
520523
)
521524
);
522525
} else {

0 commit comments

Comments
 (0)