Skip to content

Commit f287f9f

Browse files
aarspixelhandler
authored andcommitted
Fix broken model blueprint & add blueprint tests (#98)
1 parent 376591d commit f287f9f

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/config/ember-try.js
33
/dist
44
/tests
5+
/node-tests
56
/tmp
67
**/.gitkeep
78
.bowerrc

blueprints/jsonapi-resource/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,16 @@ module.exports = {
5757
var modelOptions = merge({}, options, {
5858
entity: {
5959
name: entityName ? inflection.singularize(entityName) : ''
60-
},
61-
originBlueprintName: 'jsonapi-model'
60+
}
6261
});
6362

6463
var otherOptions = merge({}, options);
6564

6665
return Promise.all([
6766
this._processBlueprint(type, 'jsonapi-model', modelOptions),
68-
this._processBlueprint(type, 'addon-import', modelOptions),
6967
this._processBlueprint(type, 'jsonapi-adapter', otherOptions),
7068
this._processBlueprint(type, 'jsonapi-serializer', otherOptions),
7169
this._processBlueprint(type, 'jsonapi-service', otherOptions),
72-
this._processBlueprint(type, 'jsonapi-adapter', otherOptions),
7370
this._processBlueprint(type, 'jsonapi-initializer', otherOptions)
7471
]);
7572
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use strict';
2+
3+
var EOL = require('os').EOL;
4+
var blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
5+
var setupTestHooks = blueprintHelpers.setupTestHooks;
6+
var emberNew = blueprintHelpers.emberNew;
7+
var emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
8+
var emberGenerate = blueprintHelpers.emberGenerate;
9+
10+
var expect = require('ember-cli-blueprint-test-helpers/chai').expect;
11+
var sleep = require('sleep');
12+
13+
describe('Acceptance: ember generate and destroy jsonapi-resource', function() {
14+
setupTestHooks(this);
15+
16+
it('generates jsonapi-resource files (model, serializer, adapter, service, tests)', function() {
17+
var args = ['jsonapi-resource', 'foo'];
18+
19+
return emberNew()
20+
.then(() => emberGenerateDestroy(args, (file) => {
21+
// model & unit test
22+
expect(file('app/models/foo.js'))
23+
.to.contain("import Ember from 'ember';"+EOL)
24+
.to.contain("import Resource from 'ember-jsonapi-resources/models/resource';"+EOL)
25+
.to.contain("import { attr, hasOne, hasMany } from 'ember-jsonapi-resources/models/resource';"+EOL);
26+
expect(file('tests/unit/models/foo-test.js'))
27+
.to.contain("import Ember from 'ember';"+EOL)
28+
.to.contain("import Model from '../../../models/foo';"+EOL)
29+
.to.contain("import { moduleFor, test } from 'ember-qunit';"+EOL);
30+
31+
// serializer and tests
32+
expect(file('app/serializers/foo.js'))
33+
.to.contain("import ApplicationSerializer from './application';"+EOL)
34+
.to.contain("export default ApplicationSerializer.extend({"+EOL)
35+
// we're not testing the body here
36+
.to.contain("});"+EOL);
37+
expect(file('tests/unit/serializers/foo-test.js'))
38+
.to.contain("import Ember from 'ember';"+EOL)
39+
.to.contain("import Resource from '../../../models/foo';"+EOL)
40+
.to.contain("import { moduleFor, test } from 'ember-qunit';"+EOL);
41+
42+
// adapter and tests
43+
expect(file('app/adapters/foo.js'))
44+
.to.contain("import ApplicationAdapter from './application';"+EOL)
45+
.to.contain("import config from '../config/environment';"+EOL)
46+
.to.contain("export default ApplicationAdapter.extend({"+EOL)
47+
// we're not testing the body here, except for type
48+
.to.contain("type: 'foo',"+EOL)
49+
.to.contain("});"+EOL);
50+
expect(file('tests/unit/adapters/foo-test.js'))
51+
.to.contain("import { moduleFor, test } from 'ember-qunit';"+EOL);
52+
53+
// service and tests
54+
expect(file('app/services/foos.js'))
55+
.to.contain("import Adapter from '../adapters/foo';"+EOL)
56+
.to.contain("import ServiceCache from '../mixins/service-cache';"+EOL)
57+
.to.contain("Adapter.reopenClass({ isServiceFactory: true });"+EOL)
58+
.to.contain("export default Adapter.extend(ServiceCache);"+EOL);
59+
expect(file('tests/unit/services/foos-test.js'))
60+
.to.contain("import { moduleFor, test } from 'ember-qunit';"+EOL);
61+
}));
62+
});
63+
});

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"scripts": {
1010
"build": "ember build",
1111
"start": "ember server",
12-
"test": "ember try:each"
12+
"test": "ember try:each",
13+
"nodetest": "mocha node-tests --recursive"
1314
},
1415
"repository": "[email protected]:pixelhandler/ember-jsonapi-resources.git",
1516
"engines": {
@@ -26,6 +27,7 @@
2627
"ember-buffered-proxy": "^0.5.1",
2728
"ember-cli": "2.8.0",
2829
"ember-cli-app-version": "^1.0.0",
30+
"ember-cli-blueprint-test-helpers": "^0.13.0",
2931
"ember-cli-content-security-policy": "0.4.0",
3032
"ember-cli-dependency-checker": "^1.2.0",
3133
"ember-cli-get-dependency-depth": "^1.0.0",
@@ -49,6 +51,7 @@
4951
"glob": "^4.5.3",
5052
"http-proxy": "^1.12.0",
5153
"loader.js": "^4.0.1",
54+
"mocha": "^2.5.3",
5255
"morgan": "^1.6.1",
5356
"silent-error": "^1.0.0",
5457
"yuidocjs": "^0.7.0"

0 commit comments

Comments
 (0)