/
test-model.js
70 lines (59 loc) · 2.63 KB
/
test-model.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*global describe:true, beforeEach:true, it:true */
'use strict';
var path = require('path');
var helpers = require('yeoman-generator').test;
var assert = require('assert');
var fs = require('fs');
require('fleck');
require('./helpers/expected_model_files');
describe('Model', function () {
beforeEach(function (done) {
helpers.testDirectory(path.join(__dirname, './temp'), function (err) {
done();
}.bind(this));
});
var filesDoNotExist = function(list_of_files){
for (var i = 0; i < list_of_files.length; i++) {
assert(!fs.existsSync(list_of_files[i]));
}
};
//it('takes singular noun and creates singular route, controller, template for edit')
//it('takes singular noun and registers singular and plural routes with router')
//it('takes singular noun and creates plural route, template for read of all')
//it('takes singular noun and creates singular controller, template for read')
it('with javascript', function (done) {
this.model = {};
var cmd_line_args = ['User', 'name:string', 'zipcode:number'];
this.model = helpers.createGenerator('ember:model',
['../../model','../../controller','../../view','../../router'],
cmd_line_args);
filesDoNotExist(JS_FILES_GENERATED_BY_MODEL_SUBGEN);
var model = this.model;
this.model.run({}, function () {
helpers.assertFiles( JS_FILES_GENERATED_BY_MODEL_SUBGEN );
helpers.assertFile('app/scripts/models/user_model.js', /User = DS.Model/);
helpers.assertFile('app/scripts/models/user_model.js', /name: DS.attr\('string'\)/);
helpers.assertFile('app/scripts/models/user_model.js', /zipcode: DS.attr\('number'\)/);
helpers.assertFile('app/scripts/models/user_model.js', /User.FIXTURES/);
done();
});
});
it('with coffeescript', function (done) {
this.model = {};
var cmd_line_args = ['User', 'name:string', 'zipcode:number'];
this.model = helpers.createGenerator('ember:model',
['../../model','../../controller','../../view','../../router'],
cmd_line_args);
filesDoNotExist(COFFEE_FILES_GENERATED_BY_MODEL_SUBGEN);
var model = this.model;
this.model.options.coffee = true;
this.model.run({}, function () {
helpers.assertFiles( COFFEE_FILES_GENERATED_BY_MODEL_SUBGEN );
helpers.assertFile('app/scripts/models/user_model.coffee', /User = DS.Model/);
helpers.assertFile('app/scripts/models/user_model.coffee', /name: DS.attr\('string'\)/);
helpers.assertFile('app/scripts/models/user_model.coffee', /zipcode: DS.attr\('number'\)/);
helpers.assertFile('app/scripts/models/user_model.coffee', /User.FIXTURES/);
done();
});
});
});