Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/persisted-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ module.exports = function(registry) {
description: 'Create a new instance of the model and persist it into the data source.',
accessType: 'WRITE',
accepts: {
arg: 'data', type: 'object', model: typeName,
arg: 'data', type: 'object', model: typeName, allowArray: true,
description: 'Model instance data',
http: { source: 'body' },
},
Expand Down
38 changes: 38 additions & 0 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,44 @@ describe.onServer('Remote Methods', function() {
app.use(loopback.rest());
});

describe('Model.create(data, callback)', function() {
it('creates model', function(done) {
var anObject = { first: 'June' };
request(app)
.post('/users')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i noticed the other test cases in this describe is using the method itself instead of going thru strong-remoting
like User.destroyAll(....), instead of POST /users/destroyAll, but that wouldnt be able to verify our scenario that strong-remoting rejects the array. should i add comments to describe why its different?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destroyAll is not exposed via REST.

should i add comments to describe why its different?

yes please, that would be helpful

// sends an object
.send(anObject)
.expect('Content-Type', /json/)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.have.property('id');
expect(res.body).to.have.property('first', 'June');
done();
});
});
// batch create must be tested with a remote request because there are
// coercion being done on strong-remoting side
it('creates array of models', function(done) {
var arrayOfObjects = [
{ first: 'John' }, { first: 'Jane' },
];
request(app)
.post('/users')
// sends an array of objects
.send(arrayOfObjects)
.expect('Content-Type', /json/)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body.length).to.eql(2);
expect(res.body).to.have.deep.property('[0].first', 'John');
expect(res.body).to.have.deep.property('[1].first', 'Jane');
done();
});
});
});
// destoryAll is not exposed as a remoteMethod by default
describe('Model.destroyAll(callback)', function() {
it('Delete all Model instances from data source', function(done) {
(new TaskEmitter())
Expand Down