Permalink
Browse files

feat: can pass singular model name to resource helper

  • Loading branch information...
Andy Brown authored and samselikoff committed Oct 29, 2017
1 parent d310ea2 commit a624549331e2878c154aac1f48d5fcd6ef0c2d7a
Showing with 40 additions and 0 deletions.
  1. +1 −0 addon/server.js
  2. +39 −0 tests/integration/server/resource-shorthand-test.js
View
@@ -429,6 +429,7 @@ export default class Server {
}
resource(resourceName, { only, except, path } = {}) {
resourceName = pluralize(resourceName);
path = path || `/${resourceName}`;
only = only || [];
except = except || [];
@@ -273,6 +273,45 @@ module('Integration | Server | Resource shorthand', function(hooks) {
});
});
test('resource accepts singular name', function(assert) {
assert.expect(3);
let done = assert.async(2);
this.server.db.loadData({
contacts: [
{ id: 1, name: 'Link' },
{ id: 2, name: 'Zelda' }
],
blogPosts: [
{ id: 1, title: 'Post 1' },
{ id: 2, title: 'Post 2' }
]
});
this.server.resource('contact');
this.server.resource('blog-post', { path: '/posts' });
$.ajax({
method: 'GET',
url: '/contacts'
}).done(function(res, status, xhr) {
assert.equal(xhr.status, 200);
assert.deepEqual(res, { contacts: [{ id: '1', name: 'Link' }, { id: '2', name: 'Zelda' }] });
done();
});
$.ajax({
method: 'GET',
url: '/posts'
}).fail((xhr, textStatus, error) => {
assert.ok(false, 'failed to find custom path');
done();
}).done(function(res, status, xhr) {
assert.ok(true);
done();
});
});
test('resource does not accept both :all and :except options', function(assert) {
let { server } = this;

0 comments on commit a624549

Please sign in to comment.