Commit 2b8a941e authored by Caleb Weeks's avatar Caleb Weeks

altering how the selectors are added in some cases

parent 8399967f
......@@ -215,7 +215,7 @@ SC.getSling = function(path, options = {}, callback){
//deref selector
if(this.hasDerefCapability){
if(this.hasDerefCapability ){
if((this.derefByDefault && !options.dontDeref) || options.deref){
//inject as the first selector
path = sc_self.util.addSelector(path, selectors.deref);
......@@ -225,11 +225,11 @@ SC.getSling = function(path, options = {}, callback){
// get if exists selector
const useGetIfExists =
this.hasGetIfExistsCapabililty && //is the capability enabled
path.match(/\.json$/) && // is this request a candidate (anything that just ends with .json)
path.match(/^\/(content|etc)\/.*\.json$/) && // is this request a candidate (anything under content or etc that just ends with .json)
((this.useGetIfExistsByDefault && !options.dontUseGetIfExists) || options.useGetIfExists); //and this request should use
if(useGetIfExists){
//inject as the first selector
path = sc_self.util.addSelector(path, selectors.getIfExists);
path = sc_self.util.addSelector(path, selectors.getIfExists, 'json');
}
......@@ -814,11 +814,26 @@ SC.util.getNonMeta=function(data, keyProperty, iterator){
}
SC.util.addSelector = (path, selector) => {
SC.util.addSelector = (path, selector, extensionCheck) => {
//inject as the first selector
let pathParts = path.split(".");
pathParts.splice(1, 0, selector);
return pathParts.join(".");
if(extensionCheck){
//first split into path parts
let pathParts = path.split("/");
//find the segment that has the indicated extension and modify it
return pathParts.map((segment) => {
if(_.endsWith(segment, extensionCheck)){
let segmentParts = segment.split(".");
segmentParts.splice(1, 0, selector);
segment = segmentParts.join('.');
}
return segment;
}).join("/");
}else{
let pathParts = path.split(".");
pathParts.splice(1, 0, selector);
return pathParts.join(".");
}
}
......
module.exports = jest.fn(function (reqOptions, reqCallback) {
let testUri = reqOptions.uri;
testUri = testUri.replace("/content/", "/").replace("/etc/", "/");
let uriParts = testUri.split('/');
let fixturesIndex = uriParts.indexOf('__fixtures__');
uriParts.splice(fixturesIndex + 1, 0, 'request');
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment