Merge pull request #6240 from halfdan/6239-ghost-api
Fix non-idempotent Ghost API helper
This commit is contained in:
commit
fe91944d43
@ -30,7 +30,8 @@
|
||||
url = {
|
||||
api: function () {
|
||||
var args = Array.prototype.slice.call(arguments),
|
||||
queryOptions;
|
||||
queryOptions,
|
||||
requestUrl = apiUrl;
|
||||
|
||||
if (args.length && typeof args[args.length - 1] === 'object') {
|
||||
queryOptions = args.pop();
|
||||
@ -43,11 +44,11 @@
|
||||
|
||||
if (args.length) {
|
||||
args.forEach(function (el) {
|
||||
apiUrl += el.replace(/^\/|\/$/g, '') + '/';
|
||||
requestUrl += el.replace(/^\/|\/$/g, '') + '/';
|
||||
});
|
||||
}
|
||||
|
||||
return apiUrl + generateQueryString(queryOptions);
|
||||
return requestUrl + generateQueryString(queryOptions);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -127,4 +127,20 @@ describe('Ghost Ajax Helper', function () {
|
||||
rendered.should.match(/include=tags%2Ctests/);
|
||||
rendered.should.match(/page=2/);
|
||||
});
|
||||
|
||||
it('should be idempotent', function () {
|
||||
configUtils.set({
|
||||
url: 'https://testblog.com/blog/'
|
||||
});
|
||||
ghostUrl.init({
|
||||
clientId: 'ghost-frontend',
|
||||
clientSecret: 'notasecret',
|
||||
url: configUtils.config.apiUrl()
|
||||
});
|
||||
|
||||
var rendered = ghostUrl.url.api('posts', {limit: 3}),
|
||||
rendered2 = ghostUrl.url.api('posts', {limit: 3});
|
||||
|
||||
rendered.should.equal(rendered2);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user