0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Renamed urlService.getUrl to urlService.getUrlByResourceId

no issue

- explicit function naming
- no functional change, only renaming
This commit is contained in:
kirrg001 2018-04-25 19:37:39 +02:00
parent e23fd511eb
commit ab5199267b
3 changed files with 48 additions and 48 deletions

View file

@ -375,7 +375,7 @@ Post = ghostBookshelf.Model.extend({
* - `author_id`: /:author/:slug, /:primary_author/:slug * - `author_id`: /:author/:slug, /:primary_author/:slug
* - @TODO: with channels, we no longer need these * - @TODO: with channels, we no longer need these
* - because the url service pre-generates urls based on the resources * - because the url service pre-generates urls based on the resources
* - you can ask `urlService.getUrl(post.id)` * - you can ask `urlService.getUrlByResourceId(post.id)`
* - @TODO: there is currently a bug in here * - @TODO: there is currently a bug in here
* - you request `fields=title,url` * - you request `fields=title,url`
* - you don't use `include=tags` * - you don't use `include=tags`

View file

@ -117,7 +117,7 @@ class UrlService {
/** /**
* Get url by resource id. * Get url by resource id.
*/ */
getUrl(id) { getUrlByResourceId(id) {
const obj = this.urls.getByResourceId(id); const obj = this.urls.getByResourceId(id);
if (obj) { if (obj) {

View file

@ -167,43 +167,43 @@ describe('Unit: services/url/UrlService', function () {
} }
}); });
let url = urlService.getUrl(testUtils.DataGenerator.forKnex.posts[0].id); let url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.posts[0].id);
url.should.eql('/html-ipsum/'); url.should.eql('/html-ipsum/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.posts[1].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.posts[1].id);
url.should.eql('/ghostly-kitchen-sink/'); url.should.eql('/ghostly-kitchen-sink/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.posts[2].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.posts[2].id);
should.not.exist(url); should.not.exist(url);
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[0].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[0].id);
url.should.eql('/tag/kitchen-sink/'); url.should.eql('/tag/kitchen-sink/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[1].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[1].id);
url.should.eql('/tag/bacon/'); url.should.eql('/tag/bacon/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[2].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[2].id);
url.should.eql('/tag/chorizo/'); url.should.eql('/tag/chorizo/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[3].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[3].id);
url.should.eql('/tag/pollo/'); url.should.eql('/tag/pollo/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[4].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[4].id);
url.should.eql('/tag/injection/'); url.should.eql('/tag/injection/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[0].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[0].id);
url.should.eql('/author/joe-bloggs/'); url.should.eql('/author/joe-bloggs/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[1].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[1].id);
url.should.eql('/author/smith-wellingsworth/'); url.should.eql('/author/smith-wellingsworth/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[2].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[2].id);
url.should.eql('/author/jimothy-bogendath/'); url.should.eql('/author/jimothy-bogendath/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[3].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[3].id);
url.should.eql('/author/slimer-mcectoplasm/'); url.should.eql('/author/slimer-mcectoplasm/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[4].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[4].id);
url.should.eql('/author/contributor/'); url.should.eql('/author/contributor/');
}); });
@ -220,7 +220,7 @@ describe('Unit: services/url/UrlService', function () {
return models.Post.edit({featured: true}, {id: testUtils.DataGenerator.forKnex.posts[1].id}) return models.Post.edit({featured: true}, {id: testUtils.DataGenerator.forKnex.posts[1].id})
.then(function (post) { .then(function (post) {
// There is no collection which owns featured posts. // There is no collection which owns featured posts.
let url = urlService.getUrl(post.id); let url = urlService.getUrlByResourceId(post.id);
should.not.exist(url); should.not.exist(url);
urlService.urlGenerators.forEach(function (generator) { urlService.urlGenerators.forEach(function (generator) {
@ -238,7 +238,7 @@ describe('Unit: services/url/UrlService', function () {
it('page: false => page:true', function () { it('page: false => page:true', function () {
return models.Post.edit({page: true}, {id: testUtils.DataGenerator.forKnex.posts[1].id}) return models.Post.edit({page: true}, {id: testUtils.DataGenerator.forKnex.posts[1].id})
.then(function (post) { .then(function (post) {
let url = urlService.getUrl(post.id); let url = urlService.getUrlByResourceId(post.id);
url.should.eql('/ghostly-kitchen-sink/'); url.should.eql('/ghostly-kitchen-sink/');
@ -257,7 +257,7 @@ describe('Unit: services/url/UrlService', function () {
it('page: true => page:false', function () { it('page: true => page:false', function () {
return models.Post.edit({page: false}, {id: testUtils.DataGenerator.forKnex.posts[5].id}) return models.Post.edit({page: false}, {id: testUtils.DataGenerator.forKnex.posts[5].id})
.then(function (post) { .then(function (post) {
let url = urlService.getUrl(post.id); let url = urlService.getUrlByResourceId(post.id);
url.should.eql('/static-page-test/'); url.should.eql('/static-page-test/');
@ -283,7 +283,7 @@ describe('Unit: services/url/UrlService', function () {
title: 'Brand New Story!', title: 'Brand New Story!',
author_id: testUtils.DataGenerator.forKnex.users[4].id author_id: testUtils.DataGenerator.forKnex.users[4].id
}).then(function (post) { }).then(function (post) {
let url = urlService.getUrl(post.id); let url = urlService.getUrlByResourceId(post.id);
url.should.eql('/brand-new-story/'); url.should.eql('/brand-new-story/');
let resource = urlService.getResource(url); let resource = urlService.getResource(url);
@ -299,7 +299,7 @@ describe('Unit: services/url/UrlService', function () {
title: 'Brand New Story!', title: 'Brand New Story!',
author_id: testUtils.DataGenerator.forKnex.users[4].id author_id: testUtils.DataGenerator.forKnex.users[4].id
}).then(function (post) { }).then(function (post) {
let url = urlService.getUrl(post.id); let url = urlService.getUrlByResourceId(post.id);
should.not.exist(url); should.not.exist(url);
let resource = urlService.getResource(url); let resource = urlService.getResource(url);
@ -461,44 +461,44 @@ describe('Unit: services/url/UrlService', function () {
} }
}); });
let url = urlService.getUrl(testUtils.DataGenerator.forKnex.posts[0].id); let url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.posts[0].id);
url.should.eql('/collection/2015/html-ipsum/'); url.should.eql('/collection/2015/html-ipsum/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.posts[1].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.posts[1].id);
url.should.eql('/collection/2015/ghostly-kitchen-sink/'); url.should.eql('/collection/2015/ghostly-kitchen-sink/');
// featured // featured
url = urlService.getUrl(testUtils.DataGenerator.forKnex.posts[2].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.posts[2].id);
url.should.eql('/podcast/short-and-sweet/'); url.should.eql('/podcast/short-and-sweet/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[0].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[0].id);
url.should.eql('/category/kitchen-sink/'); url.should.eql('/category/kitchen-sink/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[1].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[1].id);
url.should.eql('/category/bacon/'); url.should.eql('/category/bacon/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[2].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[2].id);
url.should.eql('/category/chorizo/'); url.should.eql('/category/chorizo/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[3].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[3].id);
url.should.eql('/category/pollo/'); url.should.eql('/category/pollo/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[4].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[4].id);
url.should.eql('/category/injection/'); url.should.eql('/category/injection/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[0].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[0].id);
url.should.eql('/persons/joe-bloggs/'); url.should.eql('/persons/joe-bloggs/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[1].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[1].id);
url.should.eql('/persons/smith-wellingsworth/'); url.should.eql('/persons/smith-wellingsworth/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[2].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[2].id);
url.should.eql('/persons/jimothy-bogendath/'); url.should.eql('/persons/jimothy-bogendath/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[3].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[3].id);
url.should.eql('/persons/slimer-mcectoplasm/'); url.should.eql('/persons/slimer-mcectoplasm/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[4].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[4].id);
url.should.eql('/persons/contributor/'); url.should.eql('/persons/contributor/');
}); });
@ -507,7 +507,7 @@ describe('Unit: services/url/UrlService', function () {
return models.Post.edit({featured: true}, {id: testUtils.DataGenerator.forKnex.posts[1].id}) return models.Post.edit({featured: true}, {id: testUtils.DataGenerator.forKnex.posts[1].id})
.then(function (post) { .then(function (post) {
// There is no collection which owns featured posts. // There is no collection which owns featured posts.
let url = urlService.getUrl(post.id); let url = urlService.getUrlByResourceId(post.id);
url.should.eql('/podcast/ghostly-kitchen-sink/'); url.should.eql('/podcast/ghostly-kitchen-sink/');
urlService.urlGenerators.forEach(function (generator) { urlService.urlGenerators.forEach(function (generator) {
@ -526,7 +526,7 @@ describe('Unit: services/url/UrlService', function () {
return models.Post.edit({featured: false}, {id: testUtils.DataGenerator.forKnex.posts[2].id}) return models.Post.edit({featured: false}, {id: testUtils.DataGenerator.forKnex.posts[2].id})
.then(function (post) { .then(function (post) {
// There is no collection which owns featured posts. // There is no collection which owns featured posts.
let url = urlService.getUrl(post.id); let url = urlService.getUrlByResourceId(post.id);
url.should.eql('/collection/2015/short-and-sweet/'); url.should.eql('/collection/2015/short-and-sweet/');
urlService.urlGenerators.forEach(function (generator) { urlService.urlGenerators.forEach(function (generator) {
@ -698,44 +698,44 @@ describe('Unit: services/url/UrlService', function () {
} }
}); });
let url = urlService.getUrl(testUtils.DataGenerator.forKnex.posts[0].id); let url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.posts[0].id);
url.should.eql('/blog/collection/2015/html-ipsum/'); url.should.eql('/blog/collection/2015/html-ipsum/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.posts[1].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.posts[1].id);
url.should.eql('/blog/collection/2015/ghostly-kitchen-sink/'); url.should.eql('/blog/collection/2015/ghostly-kitchen-sink/');
// featured // featured
url = urlService.getUrl(testUtils.DataGenerator.forKnex.posts[2].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.posts[2].id);
url.should.eql('/blog/podcast/short-and-sweet/'); url.should.eql('/blog/podcast/short-and-sweet/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[0].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[0].id);
url.should.eql('/blog/category/kitchen-sink/'); url.should.eql('/blog/category/kitchen-sink/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[1].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[1].id);
url.should.eql('/blog/category/bacon/'); url.should.eql('/blog/category/bacon/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[2].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[2].id);
url.should.eql('/blog/category/chorizo/'); url.should.eql('/blog/category/chorizo/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[3].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[3].id);
url.should.eql('/blog/category/pollo/'); url.should.eql('/blog/category/pollo/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.tags[4].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.tags[4].id);
url.should.eql('/blog/category/injection/'); url.should.eql('/blog/category/injection/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[0].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[0].id);
url.should.eql('/blog/persons/joe-bloggs/'); url.should.eql('/blog/persons/joe-bloggs/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[1].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[1].id);
url.should.eql('/blog/persons/smith-wellingsworth/'); url.should.eql('/blog/persons/smith-wellingsworth/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[2].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[2].id);
url.should.eql('/blog/persons/jimothy-bogendath/'); url.should.eql('/blog/persons/jimothy-bogendath/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[3].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[3].id);
url.should.eql('/blog/persons/slimer-mcectoplasm/'); url.should.eql('/blog/persons/slimer-mcectoplasm/');
url = urlService.getUrl(testUtils.DataGenerator.forKnex.users[4].id); url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[4].id);
url.should.eql('/blog/persons/contributor/'); url.should.eql('/blog/persons/contributor/');
}); });
}); });