Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
prefix models names
Browse files Browse the repository at this point in the history
  • Loading branch information
g13013 committed Mar 16, 2016
1 parent 29e1245 commit bebfd72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
5 changes: 2 additions & 3 deletions lib/module_app_interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ class ModuleAppInterface {

model (name, schema, collection, skipinit) {
let app = map.get(this);
name = strings.classify(name);

if (schema) {
if (!(schema instanceof this.Schema)) {
schema = new this.Schema(schema);
}
this.schemas[name] = schema;
this.schemas[utils.classify(name)] = schema;
}

return app.db.model(name, schema, collection, skipinit);
return app.db.model(strings.classify(`${this.moduleName}_${name}`), schema, collection, skipinit);
}

getSchema (name, module) {
Expand Down
16 changes: 8 additions & 8 deletions test/spec/module_app_interface_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ModuleAppInterface', function () {
app.Router = jasmine.createSpy('appRouter').and.returnValue(router);
app.Schema = jasmine.createSpy('app.Schema');
});

describe('#generateIndexRouteHandler', function () {
it ('it returns a generator function', function() {
var inter = new ModuleAppInterface('my_module', desc, app);
Expand Down Expand Up @@ -67,9 +67,9 @@ describe('ModuleAppInterface', function () {
var schema = new app.Schema();
var inter = new ModuleAppInterface('my_module', desc, app);
inter.model('model_name', schema, 3, 4);
expect(app.db.model).toHaveBeenCalledWith('ModelName', schema, 3, 4);
inter.model('model_name', false, 3, 4);
expect(app.db.model).toHaveBeenCalledWith('ModelName', false, 3, 4);
expect(app.db.model).toHaveBeenCalledWith('MyModuleModelName', schema, 3, 4);
inter.model('model_name_2', false, 3, 4);
expect(app.db.model).toHaveBeenCalledWith('MyModuleModelName2', false, 3, 4);
});

it('creates new instance of Schema if schema is object', function () {
Expand All @@ -85,10 +85,10 @@ describe('ModuleAppInterface', function () {
this.prop = 'instance';
});

let obj = new ModuleAppInterface('my_module', desc, app);
obj.model('name', schema);
expect(obj.schemas.Name).toEqual(jasmine.objectContaining({prop: 'instance'}));
expect(app.schemas.my_module).toEqual(jasmine.objectContaining({Name: obj.schemas.Name}));
let obj = new ModuleAppInterface('module', desc, app);
obj.model('model_name', schema);
expect(obj.schemas.ModelName).toEqual(jasmine.objectContaining({prop: 'instance'}));
expect(app.schemas.module).toEqual(jasmine.objectContaining({ModelName: obj.schemas.ModelName}));
});
});

Expand Down

0 comments on commit bebfd72

Please sign in to comment.