Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions box.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
"commandbox-cfformat":"*",
"commandbox-docbox":"*",
"commandbox-dotenv":"*",
"commandbox-cfconfig":"*"
"commandbox-cfconfig":"*",
"cbMockData":"^4.1.0+3"
},
"installPaths":{
"cbMockData":"modules/cbMockData/"
},
"installPaths":{},
"ignore":[
"**/.*",
"build/**",
Expand Down
44 changes: 23 additions & 21 deletions interceptors/Mementifier.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ component {
};

// Param arguments according to instance > settings chain precedence
arguments.trustedGetters = isNull( arguments.trustedGetters ) ? thisMemento.trustedGetters : arguments.trustedGetters;
arguments.iso8601Format = isNull( arguments.iso8601Format ) ? thisMemento.iso8601Format : arguments.iso8601Format;
arguments.dateMask = isNull( arguments.dateMask ) ? thisMemento.dateMask : arguments.dateMask;
arguments.timeMask = isNull( arguments.timeMask ) ? thisMemento.timeMask : arguments.timeMask;
arguments.autoCastBooleans = isNull( arguments.autoCastBooleans ) ? thisMemento.autoCastBooleans : arguments.autoCastBooleans;
var flags = {
"trustedGetters" = isNull( arguments.trustedGetters ) ? thisMemento.trustedGetters : arguments.trustedGetters,
"iso8601Format" = isNull( arguments.iso8601Format ) ? thisMemento.iso8601Format : arguments.iso8601Format,
"dateMask" = isNull( arguments.dateMask ) ? thisMemento.dateMask : arguments.dateMask,
"timeMask" = isNull( arguments.timeMask ) ? thisMemento.timeMask : arguments.timeMask,
"autoCastBooleans" = isNull( arguments.autoCastBooleans ) ? thisMemento.autoCastBooleans : arguments.autoCastBooleans
};

// Choose a profile
if ( len( arguments.profile ) && thisMemento.profiles.keyExists( arguments.profile ) ) {
Expand All @@ -178,9 +180,9 @@ component {

// Default formatter or customize it if passed arguments are different than settings.
var customDateFormatter = this.$FORMATTER_CUSTOM;
if ( arguments.dateMask != thisMemento.dateMask || arguments.timeMask != thisMemento.timeMask ) {
if ( flags.dateMask != thisMemento.dateMask || flags.timeMask != thisMemento.timeMask ) {
customDateFormatter = createObject( "java", "java.text.SimpleDateFormat" ).init(
"#arguments.dateMask# #arguments.timeMask#"
"#flags.dateMask# #flags.timeMask#"
);
}

Expand Down Expand Up @@ -275,12 +277,12 @@ component {
var thisAlias = item;
}

if ( arguments.trustedGetters || structKeyExists( this, "get#item#" ) ) {
if ( flags.trustedGetters || structKeyExists( this, "get#item#" ) ) {
try {
thisValue = invoke( this, "get#item#" );
} catch ( any e ) {
// Unless trusted getters is on and there is a mapper for this item rethrow the exception.
if ( !arguments.trustedGetters || !structKeyExists( arguments.mappers, item ) ) {
if ( !flags.trustedGetters || !structKeyExists( arguments.mappers, item ) ) {
rethrow;
}
}
Expand Down Expand Up @@ -319,7 +321,7 @@ component {
// Date Test just in case
dateInstance.getTime();
// Iso Date?
if ( arguments.iso8601Format ) {
if ( flags.iso8601Format ) {
// we need to convert trailing Zulu time designations offset or JS libs like Moment will not know how to parse it
result[ thisAlias ] = this.$FORMATTER_ISO8601.format( dateInstance ).replace( "Z", "+00:00" );
} else {
Expand All @@ -331,7 +333,7 @@ component {
}

// Strict Type Boolean Values
else if ( arguments.autoCastBooleans && !isNumeric( thisValue ) && isBoolean( thisValue ) ) {
else if ( flags.autoCastBooleans && !isNumeric( thisValue ) && isBoolean( thisValue ) ) {
result[ thisAlias ] = javacast( "Boolean", thisValue );
}

Expand Down Expand Up @@ -366,11 +368,11 @@ component {
ignoreDefaults : nestedIncludes.len() ? arguments.ignoreDefaults : false,
// Cascade the arguments to the children
profile : arguments.profile,
trustedGetters : arguments.trustedGetters,
iso8601Format : arguments.iso8601Format,
dateMask : arguments.dateMask,
timeMask : arguments.timeMask,
autoCastBooleans: arguments.autoCastBooleans
trustedGetters : isNull( arguments.trustedGetters ) ? javacast( "null", "" ) : arguments.trustedGetters,
iso8601Format : isNull( arguments.iso8601Format ) ? javacast( "null", "" ) : arguments.iso8601Format,
dateMask : isNull( arguments.dateMask ) ? javacast( "null", "" ) : arguments.dateMask,
timeMask : isNull( arguments.timeMask ) ? javacast( "null", "" ) : arguments.timeMask,
autoCastBooleans: isNull( arguments.autoCastBooleans ) ? javacast( "null", "" ) : arguments.autoCastBooleans
);
} else {
result[ thisAlias ][ thisIndex ] = thisValue[ thisIndex ];
Expand All @@ -396,11 +398,11 @@ component {
ignoreDefaults : nestedIncludes.len() ? arguments.ignoreDefaults : false,
// Cascade the arguments to the children
profile : arguments.profile,
trustedGetters : arguments.trustedGetters,
iso8601Format : arguments.iso8601Format,
dateMask : arguments.dateMask,
timeMask : arguments.timeMask,
autoCastBooleans: arguments.autoCastBooleans
trustedGetters : isNull( arguments.trustedGetters ) ? javacast( "null", "" ) : arguments.trustedGetters,
iso8601Format : isNull( arguments.iso8601Format ) ? javacast( "null", "" ) : arguments.iso8601Format,
dateMask : isNull( arguments.dateMask ) ? javacast( "null", "" ) : arguments.dateMask,
timeMask : isNull( arguments.timeMask ) ? javacast( "null", "" ) : arguments.timeMask,
autoCastBooleans: isNull( arguments.autoCastBooleans ) ? javacast( "null", "" ) : arguments.autoCastBooleans
);

// Do we have a root already for this guy?
Expand Down
12 changes: 6 additions & 6 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
"rewrites":{
"enable":"true"
},
"webroot":"test-harness",
"webroot":"test-harness",
"aliases":{
"/moduleroot/mementifier":"../"
}
},
"JVM":{
"heapSize":"768",
"javaVersion":"openjdk11_jre",
"JVM":{
"heapSize":"768",
"javaVersion":"openjdk11_jre",
"args":"-Dcoldfusion.runtime.remotemethod.matchArguments=false"
},
"openBrowser":"false",
"cfconfig":{
"cfconfig":{
"file":".cfconfig.json"
},
"scripts" : {
"scripts":{
"onServerInstall":"cfpm install zip,debugger,orm,mysql,postgresql,sqlserver,feed,chart"
}
}
16 changes: 10 additions & 6 deletions test-harness/handlers/Main.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
getNewSetting(),
getNewSetting(),
getNewSetting(),
getNewSetting()
getNewSetting( name = "Yes" )
] );


Expand Down Expand Up @@ -138,16 +138,20 @@
return oPost.getMemento();
}

private function getNewSetting(){
var description = "Hola!!! from #createUUID()#";
private function getNewSetting(
string name,
string description
){
param arguments.name = "setting-#createUUID()#";
param arguments.description = "Hola!!! from #arguments.name#";

return settingService.new( {
name : "setting-#createUUID()#",
description : description,
name : arguments.name,
description : arguments.description,
isConfirmed : randRange( 0, 1 )
} ).setLatestValue(
recentValueService.new( {
description : description
description : arguments.description
} )
);
}
Expand Down
7 changes: 4 additions & 3 deletions test-harness/models/Setting.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ component
"description"
],
// Default Exclusions
defaultExcludes : [],
neverInclude : [],
defaultExcludes : [],
neverInclude : [],
// Defaults
defaults : {}
defaults : {},
autoCastBooleans : false
};

/**
Expand Down
11 changes: 11 additions & 0 deletions test-harness/tests/specs/integration/MainTests.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@
.toHaveKey( "latestValue" )
.toHaveDeepKey( "description" );
} );

it( "lets nested items figure out their own default settings unless the settings were explicitly passed in arguments", function(){
var event = this.request(
route = "/",
params = { ignoreDefaults : true, includes : "fname,lname,settings" }
);
var memento = deserializeJSON( event.getRenderedContent() );
expect( memento.settings ).toBeArray().notToBeEmpty();
expect( arrayLast( memento.settings ) ).toHaveKey( "name" );
expect( arrayLast( memento.settings ).name ).toBeWithCase( "Yes" );
} );
} );
}

Expand Down
Loading