Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit dd0e75d

Browse files
author
Ryan Schumacher
committed
Add clean datasource feature
1 parent f836e19 commit dd0e75d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/helpers.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ _beforeEach.withApp = function(app) {
2626
});
2727
}
2828

29+
_beforeEach.cleanDatasource = function(dsName) {
30+
beforeEach(function() {
31+
if(!dsName) dsName = 'db';
32+
33+
if (this.app) {
34+
this.app.datasources[dsName].automigrate();
35+
this.app.datasources[dsName].connector.ids = {};
36+
}
37+
});
38+
}
39+
2940
function mixin(obj, into) {
3041
Object.keys(obj).forEach(function(key) {
3142
if(typeof obj[key] === 'function') {

test/test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,27 @@ describe('helpers', function () {
8686
});
8787
});
8888
});
89+
90+
describe('cleanDatasource', function() {
91+
helpers.describe.staticMethod('create', function() {
92+
helpers.beforeEach.withArgs({foo: 'bar'});
93+
helpers.describe.whenCalledRemotely('POST', '/xxx-test-models', function() {
94+
it('should call the method over rest', function () {
95+
assert.equal(this.res.statusCode, 200);
96+
});
97+
});
98+
});
99+
100+
helpers.describe.staticMethod('findById', function() {
101+
helpers.beforeEach.givenModel('xxx-test-model', {foo: 'bar'});
102+
helpers.beforeEach.cleanDatasource();
103+
helpers.describe.whenCalledRemotely('GET', function () {
104+
return '/xxx-test-models/' + this['xxx-test-model'].id;
105+
}, function() {
106+
it('should not find the given model', function () {
107+
assert.equal(this.res.statusCode, 404);
108+
});
109+
});
110+
});
111+
});
89112
});

0 commit comments

Comments
 (0)