mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Merge pull request #6122 from kevinansfield/slug-query-with-include
Add count.posts support to user model on client
This commit is contained in:
commit
52986b5033
5 changed files with 150 additions and 124 deletions
|
@ -34,6 +34,7 @@ export default Model.extend(ValidationEngine, {
|
||||||
embedded: 'always',
|
embedded: 'always',
|
||||||
async: false
|
async: false
|
||||||
}),
|
}),
|
||||||
|
count: DS.attr('raw'),
|
||||||
|
|
||||||
ghostPaths: inject.service('ghost-paths'),
|
ghostPaths: inject.service('ghost-paths'),
|
||||||
|
|
||||||
|
|
63
ghost/admin/tests/integration/adapters/tag-test.js
Normal file
63
ghost/admin/tests/integration/adapters/tag-test.js
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/* jshint expr:true */
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import {
|
||||||
|
describeModule,
|
||||||
|
it
|
||||||
|
} from 'ember-mocha';
|
||||||
|
import Pretender from 'pretender';
|
||||||
|
|
||||||
|
describeModule(
|
||||||
|
'adapter:tag',
|
||||||
|
'Integration: Adapter: tag',
|
||||||
|
{
|
||||||
|
integration: true
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
let server, store;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
store = this.container.lookup('service:store');
|
||||||
|
server = new Pretender();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
server.shutdown();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('loads tags from regular endpoint when all are fetched', function (done) {
|
||||||
|
server.get('/ghost/api/v0.1/tags/', function () {
|
||||||
|
return [200, {'Content-Type': 'application/json'}, JSON.stringify({tags: [{
|
||||||
|
id: 1,
|
||||||
|
name: 'Tag 1',
|
||||||
|
slug: 'tag-1'
|
||||||
|
}, {
|
||||||
|
id: 2,
|
||||||
|
name: 'Tag 2',
|
||||||
|
slug: 'tag-2'
|
||||||
|
}]})];
|
||||||
|
});
|
||||||
|
|
||||||
|
store.findAll('tag', {reload: true}).then((tags) => {
|
||||||
|
expect(tags).to.be.ok;
|
||||||
|
expect(tags.objectAtContent(0).get('name')).to.equal('Tag 1');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('loads tag from slug endpoint when single tag is queried and slug is passed in', function (done) {
|
||||||
|
server.get('/ghost/api/v0.1/tags/slug/tag-1/', function () {
|
||||||
|
return [200, {'Content-Type': 'application/json'}, JSON.stringify({tags: [{
|
||||||
|
id: 1,
|
||||||
|
slug: 'tag-1',
|
||||||
|
name: 'Tag 1'
|
||||||
|
}]})];
|
||||||
|
});
|
||||||
|
|
||||||
|
store.queryRecord('tag', {slug: 'tag-1'}).then((tag) => {
|
||||||
|
expect(tag).to.be.ok;
|
||||||
|
expect(tag.get('name')).to.equal('Tag 1');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
86
ghost/admin/tests/integration/adapters/user-test.js
Normal file
86
ghost/admin/tests/integration/adapters/user-test.js
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
/* jshint expr:true */
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import {
|
||||||
|
describeModule,
|
||||||
|
it
|
||||||
|
} from 'ember-mocha';
|
||||||
|
import Pretender from 'pretender';
|
||||||
|
|
||||||
|
describeModule(
|
||||||
|
'adapter:user',
|
||||||
|
'Integration: Adapter: user',
|
||||||
|
{
|
||||||
|
integration: true
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
let server, store;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
store = this.container.lookup('service:store');
|
||||||
|
server = new Pretender();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
server.shutdown();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('loads users from regular endpoint when all are fetched', function (done) {
|
||||||
|
server.get('/ghost/api/v0.1/users/', function () {
|
||||||
|
return [200, {'Content-Type': 'application/json'}, JSON.stringify({users: [{
|
||||||
|
id: 1,
|
||||||
|
name: 'User 1',
|
||||||
|
slug: 'user-1'
|
||||||
|
}, {
|
||||||
|
id: 2,
|
||||||
|
name: 'User 2',
|
||||||
|
slug: 'user-2'
|
||||||
|
}]})];
|
||||||
|
});
|
||||||
|
|
||||||
|
store.findAll('user', {reload: true}).then((users) => {
|
||||||
|
expect(users).to.be.ok;
|
||||||
|
expect(users.objectAtContent(0).get('name')).to.equal('User 1');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('loads user from slug endpoint when single user is queried and slug is passed in', function (done) {
|
||||||
|
server.get('/ghost/api/v0.1/users/slug/user-1/', function () {
|
||||||
|
return [200, {'Content-Type': 'application/json'}, JSON.stringify({users: [{
|
||||||
|
id: 1,
|
||||||
|
slug: 'user-1',
|
||||||
|
name: 'User 1'
|
||||||
|
}]})];
|
||||||
|
});
|
||||||
|
|
||||||
|
store.queryRecord('user', {slug: 'user-1'}).then((user) => {
|
||||||
|
expect(user).to.be.ok;
|
||||||
|
expect(user.get('name')).to.equal('User 1');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles "include" parameter when querying single user via slug', function (done) {
|
||||||
|
server.get('/ghost/api/v0.1/users/slug/user-1/', (request) => {
|
||||||
|
let params = request.queryParams;
|
||||||
|
expect(params.include, 'include query').to.equal('roles,count.posts');
|
||||||
|
|
||||||
|
return [200, {'Content-Type': 'application/json'}, JSON.stringify({users: [{
|
||||||
|
id: 1,
|
||||||
|
slug: 'user-1',
|
||||||
|
name: 'User 1',
|
||||||
|
count: {
|
||||||
|
posts: 5
|
||||||
|
}
|
||||||
|
}]})];
|
||||||
|
});
|
||||||
|
|
||||||
|
store.queryRecord('user', {slug: 'user-1', include: 'count.posts'}).then((user) => {
|
||||||
|
expect(user).to.be.ok;
|
||||||
|
expect(user.get('name')).to.equal('User 1');
|
||||||
|
expect(user.get('count.posts')).to.equal(5);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
|
@ -1,62 +0,0 @@
|
||||||
/* jshint expr:true */
|
|
||||||
import { expect } from 'chai';
|
|
||||||
import {
|
|
||||||
describeModel,
|
|
||||||
it
|
|
||||||
} from 'ember-mocha';
|
|
||||||
import Pretender from 'pretender';
|
|
||||||
|
|
||||||
describeModel('tag', 'Unit: Adapter: tag', {
|
|
||||||
needs: [
|
|
||||||
'service:ghost-paths',
|
|
||||||
'service:session',
|
|
||||||
'adapter:tag',
|
|
||||||
'serializer:tag'
|
|
||||||
]
|
|
||||||
}, function () {
|
|
||||||
let server;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
server = new Pretender();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function () {
|
|
||||||
server.shutdown();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('loads tags from regular endpoint when all are fetched', function (done) {
|
|
||||||
server.get('/ghost/api/v0.1/tags/', function () {
|
|
||||||
return [200, {'Content-Type': 'application/json'}, JSON.stringify({tags: [{
|
|
||||||
id: 1,
|
|
||||||
name: 'Tag 1',
|
|
||||||
slug: 'tag-1'
|
|
||||||
}, {
|
|
||||||
id: 2,
|
|
||||||
name: 'Tag 2',
|
|
||||||
slug: 'tag-2'
|
|
||||||
}]})];
|
|
||||||
});
|
|
||||||
|
|
||||||
this.store().findAll('tag', {reload: true}).then((tags) => {
|
|
||||||
expect(tags).to.be.ok;
|
|
||||||
expect(tags.objectAtContent(0).get('name')).to.equal('Tag 1');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('loads tag from slug endpoint when single tag is queried and slug is passed in', function (done) {
|
|
||||||
server.get('/ghost/api/v0.1/tags/slug/tag-1/', function () {
|
|
||||||
return [200, {'Content-Type': 'application/json'}, JSON.stringify({tags: [{
|
|
||||||
id: 1,
|
|
||||||
slug: 'tag-1',
|
|
||||||
name: 'Tag 1'
|
|
||||||
}]})];
|
|
||||||
});
|
|
||||||
|
|
||||||
this.store().queryRecord('tag', {slug: 'tag-1'}).then((tag) => {
|
|
||||||
expect(tag).to.be.ok;
|
|
||||||
expect(tag.get('name')).to.equal('Tag 1');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,62 +0,0 @@
|
||||||
/* jshint expr:true */
|
|
||||||
import { expect } from 'chai';
|
|
||||||
import {
|
|
||||||
describeModel,
|
|
||||||
it
|
|
||||||
} from 'ember-mocha';
|
|
||||||
import Pretender from 'pretender';
|
|
||||||
|
|
||||||
describeModel('user', 'Unit: Adapter: user', {
|
|
||||||
needs: [
|
|
||||||
'service:ghost-paths',
|
|
||||||
'service:session',
|
|
||||||
'adapter:user',
|
|
||||||
'serializer:user'
|
|
||||||
]
|
|
||||||
}, function () {
|
|
||||||
let server;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
server = new Pretender();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function () {
|
|
||||||
server.shutdown();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('loads users from regular endpoint when all are fetched', function (done) {
|
|
||||||
server.get('/ghost/api/v0.1/users/', function () {
|
|
||||||
return [200, {'Content-Type': 'application/json'}, JSON.stringify({users: [{
|
|
||||||
id: 1,
|
|
||||||
name: 'User 1',
|
|
||||||
slug: 'user-1'
|
|
||||||
}, {
|
|
||||||
id: 2,
|
|
||||||
name: 'User 2',
|
|
||||||
slug: 'user-2'
|
|
||||||
}]})];
|
|
||||||
});
|
|
||||||
|
|
||||||
this.store().findAll('user', {reload: true}).then((users) => {
|
|
||||||
expect(users).to.be.ok;
|
|
||||||
expect(users.objectAtContent(0).get('name')).to.equal('User 1');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('loads user from slug endpoint when single user is queried and slug is passed in', function (done) {
|
|
||||||
server.get('/ghost/api/v0.1/users/slug/user-1/', function () {
|
|
||||||
return [200, {'Content-Type': 'application/json'}, JSON.stringify({users: [{
|
|
||||||
id: 1,
|
|
||||||
slug: 'user-1',
|
|
||||||
name: 'User 1'
|
|
||||||
}]})];
|
|
||||||
});
|
|
||||||
|
|
||||||
this.store().queryRecord('user', {slug: 'user-1'}).then((user) => {
|
|
||||||
expect(user).to.be.ok;
|
|
||||||
expect(user.get('name')).to.equal('User 1');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Add table
Reference in a new issue