Skip to content

Commit 91b95dc

Browse files
committed
Merge pull request #16 from CleverStack/hotfix/generate-1-0-x
Update generate templates for node-seed 1.0.x
2 parents 1c51c83 + 507fc7b commit 91b95dc

13 files changed

Lines changed: 46 additions & 145 deletions

File tree

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,11 @@
1-
/**
2-
* @doc module
3-
* @name exampleModule
4-
* @description
5-
* This is an example description generated by CleverStack
6-
*/
7-
8-
/**
9-
* @doc module
10-
* @name exampleModule.controllers:{{Template}}Controller
11-
* @description
12-
* Sets up a controller within CleverStack
13-
*/
14-
module.exports = function( {{Template}}Service ) {
15-
return (require('classes').Controller).extend(
1+
module.exports = function( Controller, {{Template}}Service ) {
2+
return Controller.extend(
3+
/** @Class **/
164
{
175
service: {{Template}}Service
186
},
7+
/** @Prototype **/
198
{
209

21-
/**
22-
* 'GET/PUT/POST/DELETE /{{_template_}}/custom'
23-
*/
24-
customAction: function() {
25-
this.send({
26-
message: "Hello from customAction inside {{Template}}Controller"
27-
});
28-
},
29-
30-
/**
31-
* This function can never be called because it does not have 'Action' on the end of it
32-
*/
33-
hidden: function() {
34-
console.log('Hidden function called, this should be impossible');
35-
process.exit();
36-
}
3710
});
3811
}

templates/backend/models/odm/templateModel.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

templates/backend/models/orm/templateModel.js

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = function ( Model ) {
2+
return Model.extend( "{{Template}}",
3+
{
4+
type: 'ORM',
5+
softDeletable: true,
6+
timeStampable: true
7+
},
8+
{
9+
id: {
10+
type: Number,
11+
primaryKey: true,
12+
autoIncrement: true
13+
},
14+
name: String
15+
});
16+
};
Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
var Q = require('q')
2-
, BaseService = require( 'services' ).BaseService
3-
, {{Template}}Service;
4-
5-
{{Template}}Service = BaseService.extend({
6-
7-
});
8-
9-
module.exports = function( sequelize, ORM{{Template}}Model ) {
10-
if ( !{{Template}}Service.instance ) {
11-
{{Template}}Service.instance = new {{Template}}Service( sequelize );
12-
{{Template}}Service.Model = ORM{{Template}}Model;
13-
}
14-
15-
return {{Template}}Service.instance;
16-
};
1+
module.exports = function( Service, {{Template}}Model ) {
2+
return Service.extend({
3+
model: {{Template}}Model
4+
});
5+
}

templates/backend/tests/integration/templateTest.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,4 @@ describe ( '/{{_template_}}', function () {
8484
} );
8585
} );
8686
} );
87-
88-
describe ( 'GET /{{_template_}}/custom', function () {
89-
it ( 'should return valid status', function ( done ) {
90-
request ( app )
91-
.get ( '/{{_template_}}/custom' )
92-
.expect ( 'Content-Type', /json/ )
93-
.expect ( 200 )
94-
.end ( function ( err, res ) {
95-
if ( err ) return done ( err );
96-
expect ( res.body ).to.eql ( {
97-
message: 'Hello from customAction inside {{Template}}Controller'
98-
} );
99-
done ();
100-
} );
101-
} );
102-
} );
10387
});

templates/backend/tests/unit/templateTest.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,4 @@ describe ( 'controllers.{{Template}}Controller', function () {
9898
ctrl.deleteAction();
9999
} );
100100
} );
101-
102-
describe ( '.customAction()', function () {
103-
it ( 'should call .send() with valid arguments', function ( done ) {
104-
ctrl.send = function ( data ) {
105-
expect( data ).to.eql ( {
106-
message: 'Hello from customAction inside {{Template}}Controller'
107-
} );
108-
109-
done ();
110-
};
111-
ctrl.customAction();
112-
} );
113-
} );
114101
});

tests/generate/backend/controllers.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ describe( 'Generate backend seed (controllers)', function ( ) {
2727
expect( fs.existsSync( path.join( assetPath, 'my-new-project', 'backend', 'modules', 'Testing2', 'controllers', 'Testing2Controller.js' ) ) ).to.be.true;
2828

2929
var controller = fs.readFileSync( path.join( assetPath, 'my-new-project', 'backend', 'modules', 'Testing2', 'controllers', 'Testing2Controller.js' ) );
30-
expect( controller ).to.match( /module\.exports = function\( Testing2Service \) \{/ );
30+
expect( controller ).to.match( /module\.exports = function\( Controller, Testing2Service \) \{/ );
3131
expect( controller ).to.match( /service: Testing2Service/ );
32-
expect( controller ).to.match( /message: "Hello from customAction inside Testing2Controller"/ );
3332

3433
done( err );
3534
} );

tests/generate/backend/models.test.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ describe( 'Generate backend seed (models)', function ( ) {
2424
expect( stdout ).to.not.match( /already exists within/ );
2525

2626
expect( fs.readdirSync( path.join( assetPath, 'my-new-project', 'backend', 'modules', 'Testing2') ).length ).to.equal( 1 );
27-
expect( fs.existsSync( path.join( assetPath, 'my-new-project', 'backend', 'modules', 'Testing2', 'models', 'odm', 'Testing2Model.js' ) ) ).to.be.true;
28-
expect( fs.existsSync( path.join( assetPath, 'my-new-project', 'backend', 'modules', 'Testing2', 'models', 'odm', 'Testing2Model.js' ) ) ).to.be.true;
27+
expect( fs.existsSync( path.join( assetPath, 'my-new-project', 'backend', 'modules', 'Testing2', 'models', 'Testing2Model.js' ) ) ).to.be.true;
2928

30-
var odmModel = fs.readFileSync( path.join( assetPath, 'my-new-project', 'backend', 'modules', 'Testing2', 'models', 'odm', 'Testing2Model.js' ) );
31-
expect( odmModel ).to.match( /return mongoose\.model\('Testing2', ModelSchema\);/ );
32-
33-
var ormModel = fs.readFileSync( path.join( assetPath, 'my-new-project', 'backend', 'modules', 'Testing2', 'models', 'orm', 'Testing2Model.js' ) );
34-
expect( ormModel ).to.match( /return sequelize.define\("Testing2", \{/ );
29+
var model = fs.readFileSync( path.join( assetPath, 'my-new-project', 'backend', 'modules', 'Testing2', 'models', 'Testing2Model.js' ) );
30+
expect( model ).to.match( /return Model\.extend\( "Testing2",/ );
3531

3632
done( err );
3733
} );

tests/generate/backend/services.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ describe( 'Generate backend seed (services)', function ( ) {
2727
expect( fs.existsSync( path.join( assetPath, 'my-new-project', 'backend', 'modules', 'Testing2', 'services', 'Testing2Service.js' ) ) ).to.be.true;
2828

2929
var service = fs.readFileSync( path.join( assetPath, 'my-new-project', 'backend', 'modules', 'Testing2', 'services', 'Testing2Service.js' ) );
30-
expect( service ).to.match( /Testing2Service = BaseService.extend\(\{/ );
31-
expect( service ).to.match( /Testing2Service\.instance = new Testing2Service\( sequelize \);/ );
32-
expect( service ).to.match( /Testing2Service\.Model = ORMTesting2Model;/ );
33-
expect( service ).to.match( /return Testing2Service\.instance;/ );
30+
expect( service ).to.match( /module\.exports = function\( Service, Testing2Model \) \{/ );
31+
expect( service ).to.match( /return Service\.extend\(\{/ );
32+
expect( service ).to.match( /model\: Testing2Model/ );
3433

3534
done( err );
3635
} );

0 commit comments

Comments
 (0)