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

Commit 6dbfb94

Browse files
committed
Factor out LoopBack dep to removing coupling on the exact loopback instance.
1 parent 4546632 commit 6dbfb94

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

lib/helpers.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ _beforeEach.withArgs = function() {
5656
}
5757

5858
_beforeEach.givenModel = function(modelName, attrs, optionalHandler) {
59-
var modelKey = modelName
59+
var modelKey = modelName;
6060

6161
if(typeof attrs === 'funciton') {
6262
optionalHandler = attrs;
@@ -69,18 +69,13 @@ _beforeEach.givenModel = function(modelName, attrs, optionalHandler) {
6969

7070
attrs = attrs || {};
7171

72-
var model = loopback.getModel(modelName);
73-
74-
assert(model, 'cannot get model of name ' + modelName);
75-
7672
beforeEach(function(done) {
7773
var test = this;
78-
79-
if(!model.dataSource) {
80-
model.attachTo(this.dataSource);
81-
}
82-
83-
assert(model.dataSource, modelName + ' is not attached to a dataSource');
74+
var app = this.app;
75+
var model = app.models[modelName];
76+
assert(model, 'cannot get model of name ' + modelName + ' from app.models');
77+
assert(model.dataSource, 'cannot test model '+ modelName
78+
+ ' without attached dataSource');
8479
assert(
8580
typeof model.create === 'function',
8681
modelName + ' does not have a create method'

test/test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ describe('helpers', function () {
2323
describe('helpers.describe', function() {
2424
['staticMethod',
2525
'whenLoggedInAsUser',
26-
'whenCalledAnonymously',
27-
'model']
26+
'whenCalledAnonymously']
2827
.forEach(function(func) {
2928
it('should have a method named ' + func, function () {
3029
assert.equal(typeof helpers.describe[func], 'function');
@@ -44,10 +43,10 @@ describe('helpers', function () {
4443
});
4544

4645
describe('helpers.beforeEach.givenModel', function() {
47-
helpers.beforeEach.givenModel('AccessToken');
48-
it('should have an AccessToken property', function () {
49-
assert(this.AccessToken);
50-
assert(this.AccessToken.id);
46+
helpers.beforeEach.givenModel('xxx-test-model');
47+
it('should have an xxx-test-model property', function () {
48+
assert(this['xxx-test-model']);
49+
assert(this['xxx-test-model'].id);
5150
});
5251
});
5352

0 commit comments

Comments
 (0)