diff --git a/box.json b/box.json index f8fc7c5..99b4c83 100644 --- a/box.json +++ b/box.json @@ -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/**", diff --git a/interceptors/Mementifier.cfc b/interceptors/Mementifier.cfc index c698314..89c23ad 100644 --- a/interceptors/Mementifier.cfc +++ b/interceptors/Mementifier.cfc @@ -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 ) ) { @@ -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#" ); } @@ -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; } } @@ -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 { @@ -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 ); } @@ -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 ]; @@ -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? diff --git a/server-adobe@2021.json b/server-adobe@2021.json index 9c7c3e6..8158ecf 100644 --- a/server-adobe@2021.json +++ b/server-adobe@2021.json @@ -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" } } diff --git a/test-harness/handlers/Main.cfc b/test-harness/handlers/Main.cfc index 22ce701..27aa77c 100644 --- a/test-harness/handlers/Main.cfc +++ b/test-harness/handlers/Main.cfc @@ -45,7 +45,7 @@ getNewSetting(), getNewSetting(), getNewSetting(), - getNewSetting() + getNewSetting( name = "Yes" ) ] ); @@ -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 } ) ); } diff --git a/test-harness/models/Setting.cfc b/test-harness/models/Setting.cfc index bb0847d..757cfbb 100644 --- a/test-harness/models/Setting.cfc +++ b/test-harness/models/Setting.cfc @@ -55,10 +55,11 @@ component "description" ], // Default Exclusions - defaultExcludes : [], - neverInclude : [], + defaultExcludes : [], + neverInclude : [], // Defaults - defaults : {} + defaults : {}, + autoCastBooleans : false }; /** diff --git a/test-harness/tests/specs/integration/MainTests.cfc b/test-harness/tests/specs/integration/MainTests.cfc index 35fa1e6..eb16e1d 100644 --- a/test-harness/tests/specs/integration/MainTests.cfc +++ b/test-harness/tests/specs/integration/MainTests.cfc @@ -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" ); + } ); } ); }