Skip to content

Instantly share code, notes, and snippets.

@jasonaden
Created August 8, 2012 22:41
Show Gist options
  • Select an option

  • Save jasonaden/3299489 to your computer and use it in GitHub Desktop.

Select an option

Save jasonaden/3299489 to your computer and use it in GitHub Desktop.
Testing of toSerializable method
<cfscript>
component accessors="true" extends="Base" {
property string name;
property State state;
}
</cfscript>
<cfscript>
component accessors="true" extends="Base" {
property string name;
}
</cfscript>
<cfscript>
component accessors="true" extends="Base" {
property string name;
property StudySite studySite;
}
</cfscript>
<cfscript>
component accessors="true" extends="Base" {
property string name;
}
</cfscript>
<cfscript>
component accessors="true" extends="Base" {
property string name;
property array studyEvents;
property Site site;
}
</cfscript>
<cfscript>
component extends="mxunit.framework.TestCase" {
function testSerialize() {
// Create the data structure to test
var study = new Study({
name = 'New Study'
});
// Create the StudySite with site and state
var studySite = new StudySite({
name = 'New Study Site',
site = new Site({name = 'New Site', state = new State({name = 'VA'})})
});
study.setStudySite(studySite);
// Create an array of Study Events and assign to the StudySite
var aStudyEvents = [];
for(var i = 1 ; i <= 12 ; i++) {
arrayAppend(aStudyEvents, new StudyEvent(name = 'New StudyEvent #i#'));
}
studySite.setStudyEvents(aStudyEvents);
var serializableStruct = study.toSerializable({depth=3});
debug(serializableStruct);
var serializedWithIncludes = study.includePath('study.studySite.studyEvents')
.includePath('study.studySite.site.state')
.toSerializable();
debug(serializedWithIncludes);
}
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment