Skip to content

Commit

Permalink
bluepints/model-test: Add RFC232 variants
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-alvarez committed Dec 21, 2017
1 parent 763c5da commit 9c24224
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 28 deletions.
2 changes: 1 addition & 1 deletion blueprints/model-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = useTestFrameworkDetector({
locals: function(options) {
var result = ModelBlueprint.locals.apply(this, arguments);

result.friendlyDescription = testInfo.description(options.entity.name, "Unit", "Model");
result.friendlyTestDescription = testInfo.description(options.entity.name, "Unit", "Model");

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupModelTest } from 'ember-mocha';

describe('<%= friendlyDescription %>', function() {
describe('<%= friendlyTestDescription %>', function() {
setupModelTest('<%= dasherizedModuleName %>', {
// Specify the other units that are required for this test.
<%= typeof needs !== 'undefined' ? needs : '' %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { moduleForModel, test } from 'ember-qunit';

moduleForModel('<%= dasherizedModuleName %>', '<%= friendlyDescription %>', {
moduleForModel('<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', {
// Specify the other units that are required for this test.
<%= typeof needs !== 'undefined' ? needs : '' %>
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { run } from '@ember/runloop';

module('model:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', function(hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function(assert) {
let store = this.owner.lookup('service:store');
let model = run(() => store.createRecord('<%= dasherizedModuleName %>', {}));
assert.ok(model);
});
});
68 changes: 43 additions & 25 deletions node-tests/blueprints/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ const fixture = require('../helpers/fixture');
describe('Acceptance: generate and destroy model blueprints', function() {
setupTestHooks(this);

beforeEach(function() {
return emberNew();
});


it('model', function() {
let args = ['model', 'foo'];

return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
return emberGenerateDestroy(args, _file => {
expect(_file('app/models/foo.js'))
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.Model.extend(');

expect(_file('tests/unit/models/foo-test.js'))
.to.equal(fixture('model-test/foo-default.js'));
}));
});
});

it('model with attrs', function() {
Expand All @@ -44,8 +48,7 @@ describe('Acceptance: generate and destroy model blueprints', function() {
'customAttr:custom-transform'
];

return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
return emberGenerateDestroy(args, _file => {
expect(_file('app/models/foo.js'))
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.Model.extend(')
Expand All @@ -60,14 +63,13 @@ describe('Acceptance: generate and destroy model blueprints', function() {

expect(_file('tests/unit/models/foo-test.js'))
.to.equal(fixture('model-test/foo-default.js'));
}));
});
});

it('model with belongsTo', function() {
let args = ['model', 'comment', 'post:belongs-to', 'author:belongs-to:user'];

return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
return emberGenerateDestroy(args, _file => {
expect(_file('app/models/comment.js'))
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.Model.extend(')
Expand All @@ -76,14 +78,13 @@ describe('Acceptance: generate and destroy model blueprints', function() {

expect(_file('tests/unit/models/comment-test.js'))
.to.equal(fixture('model-test/comment-default.js'));
}));
});
});

it('model with hasMany', function() {
let args = ['model', 'post', 'comments:has-many', 'otherComments:has-many:comment'];

return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
return emberGenerateDestroy(args, _file => {
expect(_file('app/models/post.js'))
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.Model.extend(')
Expand All @@ -92,31 +93,48 @@ describe('Acceptance: generate and destroy model blueprints', function() {

expect(_file('tests/unit/models/post-test.js'))
.to.equal(fixture('model-test/post-default.js'));
}));
});
});

it('model-test', function() {
let args = ['model-test', 'foo'];

return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
return emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/models/foo-test.js'))
.to.equal(fixture('model-test/foo-default.js'));
}));
});
});

it('model-test for mocha v0.12+', function() {
let args = ['model-test', 'foo'];
describe('model-test with [email protected]', function() {
beforeEach(function() {
generateFakePackageManifest('ember-cli-qunit', '4.2.0');
});

it('model-test-test foo', function() {
return emberGenerateDestroy(['model-test', 'foo'], _file => {
expect(_file('tests/unit/models/foo-test.js'))
.to.equal(fixture('model-test/rfc232.js'));
});
});
});


describe('with ember-cli-mocha v0.12+', function() {
beforeEach(function() {
modifyPackages([
{ name: 'ember-cli-qunit', delete: true },
{ name: 'ember-cli-mocha', dev: true }
]);
generateFakePackageManifest('ember-cli-mocha', '0.12.0');
});

it('model-test for mocha v0.12+', function() {
let args = ['model-test', 'foo'];

return emberNew()
.then(() => modifyPackages([
{name: 'ember-cli-qunit', delete: true},
{name: 'ember-cli-mocha', dev: true}
]))
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.12.0'))
.then(() => emberGenerateDestroy(args, _file => {
return emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/models/foo-test.js'))
.to.equal(fixture('model-test/foo-mocha-0.12.js'));
}));
});
});
});
});
14 changes: 14 additions & 0 deletions node-tests/fixtures/model-test/rfc232.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { run } from '@ember/runloop';

module('model:foo', 'Unit | Model | foo', function(hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function(assert) {
let store = this.owner.lookup('service:store');
let model = run(() => store.createRecord('foo', {}));
assert.ok(model);
});
});

0 comments on commit 9c24224

Please sign in to comment.