Skip to content

Commit

Permalink
add additional check in _hydrate() loop over data properties and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrigsby committed Jun 22, 2024
1 parent edd350a commit d8adffe
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion models/Component.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ component output="true" {
Provide file uploads to view
*/
variables.data.each( function( key, value ) {
if ( isArray( arguments.value ) && arguments.value.len() && arguments.value[ 1 ] contains "fileupload:" ) {
if ( isArray( arguments.value ) && arguments.value.len() && isSimpleValue( arguments.value[ 1 ] ) && arguments.value[ 1 ] contains "fileupload:" ) {
// This property is holding an array of file uploads.
value.each( function( uuid, index ) {
local.fileUpload = getInstance( dsl="FileUpload@cbwire" ).load(
Expand Down
39 changes: 39 additions & 0 deletions test-harness/tests/specs/CBWIRESpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,21 @@ component extends="coldbox.system.testing.BaseTestCase" {
}
} );

it( "should handle a data property that is an array of structs", function(){
dataWithStructComponent = getInstance("wires.dataWithStructWire")._withEvent( getRequestContext( ) );
prepareMock( dataWithStructComponent );
// add aditional states
dataWithStructComponent.onMount();
dataWithStructComponent.addState( "IA", "Iowa" );
dataWithStructComponent.addState( "CA", "California" );
// verify data struct read and write without errors
var structViewContent = dataWithStructComponent.view("wires.dataWithStructWire");
expect(structViewContent).toInclude("Number Of States In data.states: 6");
expect(structViewContent).toInclude("IA : Iowa");
expect(structViewContent).toInclude("CA : California");

} );

});

describe("Incoming Requests", function() {
Expand Down Expand Up @@ -651,6 +666,30 @@ component extends="coldbox.system.testing.BaseTestCase" {
expect( snapshot.data.modules[ 2 ] ).toBe( "CBORM" );
} );

it( "should handle incoming reqeust when a data property contains an array of structs", function() {
var payload = incomingRequest(
memo = {
"name": "dataWithStructWire",
"id": "Z1Ruz1tGMPXSfw7osBW2",
"children": []
},
data = {
"title": "CBWIRE Rocks!",
"states": [
{ "name" : "Maryland", "abr" : "MD" },
{ "name" : "Virginia", "abr" : "VA" },
{ "name" : "Florida", "abr" : "FL" },
{ "name" : "Wyoming", "abr" : "WY" }
]
},
calls = [],
updates = {
"title": "CBWIRE Slaps!"
}
);
var response = cbwireController.handleRequest( payload, event );
expect( response.components[1].effects.html ).toInclude( "CBWIRE Slaps!" );
} );
} );

describe("File Uploads", function() {
Expand Down
20 changes: 20 additions & 0 deletions test-harness/wires/dataWithStructWire.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
component extends="cbwire.models.Component" {

data = [
"title": "CBWIRE Rocks!",
"states": []
];

function addState( abr, name ){
data.states.append( { "name" : name, "abr" : abr } );
}

function onMount( params, event, rc, prc ) {
// Initialize some states
data.states.append( { "name" : "Maryland", "abr" : "MD" } );
data.states.append( { "name" : "Virginia", "abr" : "VA" } );
data.states.append( { "name" : "Florida", "abr" : "FL" } );
data.states.append( { "name" : "Wyoming", "abr" : "WY" } );
}

}
14 changes: 14 additions & 0 deletions test-harness/wires/dataWithStructWire.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<cfoutput>
<div>
<div>#args.title#</div>
<h1>States</h1>
<p>Number Of States In data.states: #states.len()#</p>
<cfif states.len() >
<ul>
<cfloop index="currentIndex" item="currentState" array="#states#">
<li>#currentState.abr# : #currentState.name#</li>
</cfloop>
</ul>
</cfif>
</div>
</cfoutput>

0 comments on commit d8adffe

Please sign in to comment.