Skip to content

Commit

Permalink
Merge pull request #233 from seancorfield/develop
Browse files Browse the repository at this point in the history
Fix #232 #226 by suppressing trace output when rendering data
  • Loading branch information
seancorfield committed Dec 18, 2013
2 parents 60876d1 + 083d153 commit 5db30d8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
7 changes: 4 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<property name="mxunit.output.jar" value="tests/ci/mxunit-output-ant.jar"/>
<property name="server.name" value="localhost"/>
<property name="server.port" value="8888"/>
<property name="context.root" value="/fw1"/>
<property name="output.dir" value="tests/ci/results/"/>

<target name="install-ci-deps">
Expand Down Expand Up @@ -37,7 +38,7 @@
<taskdef classname="org.mxunit.ant.MXUnitAntTask" classpath="${mxunit.jar}" name="mxunittask"/>
<taskdef classname="au.com.imagichine.ant.MxunitOutputAntTask" classpath="${mxunit.output.jar}" name="mxunitoutputtask"/>
<mxunittask
defaultrunner="/fw1/tests/ci/HttpAntRunner.cfc"
defaultrunner="${context.root}/tests/ci/HttpAntRunner.cfc"
outputdir="${output.dir}"
port="${server.port}" server="${server.name}"
testResultsSummary="fw1.summary"
Expand All @@ -50,11 +51,11 @@
<directory
componentPath="tests"
packageName="fw1"
path="/fw1/tests/"
path="${context.root}/tests/"
recurse="false"
remoteMethod="run"/>
</mxunittask>
<mxunitoutputtask resultsdirectory="${output.dir}" />
<fail if="mxunit.error" message="An error occured running MXUnit" />
</target>
</project>
</project>
8 changes: 5 additions & 3 deletions org/corfield/framework.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,6 @@ component {

// call this to render data rather than a view and layouts
public void function renderData( string type, any data, numeric statusCode = 200 ) {
// turn off tracing so we don't interfere with the REST result:
variables.framework.trace = false;
request._fw1.renderData = { type = type, data = data, statusCode = statusCode };
}

Expand Down Expand Up @@ -1384,7 +1382,11 @@ component {
}

private void function frameworkTraceRender() {
if ( variables.framework.trace && arrayLen( request._fw1.trace ) ) {
// do not output trace information if we are rendering data as opposed
// to rendering HTML views - see #226 and #232
if ( variables.framework.trace &&
arrayLen( request._fw1.trace ) &&
!structKeyExists( request._fw1, 'renderData' ) ) {
var startTime = request._fw1.trace[1].tick;
var font = 'font-family: verdana, helvetica;';
writeOutput( '<hr /><div style="background: ##ccdddd; color: black; border: 1px solid; border-color: black; padding: 5px; #font#">' );
Expand Down
54 changes: 54 additions & 0 deletions tests/frameworkRenderTest.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
component extends="mxunit.framework.TestCase" {

public void function setUp() {
variables.fw = new org.corfield.framework();
variables.fw.enableTracing = _enableTracing;
variables.fw.enableTracing();
request.fw = new org.corfield.framework();
request.fw.enableTracing = _enableTracing;
request.fw.enableTracing();
}

private void function _enableTracing() {
variables.framework.trace = true;
}

public void function testTraceOutputVar() {
variables.fw.onApplicationStart();
var output = "";
savecontent variable="output" {
variables.fw.onRequestEnd();
}
assertTrue( output contains "framework lifecycle trace" );
}

public void function testTraceOutputReq() {
request.fw.onApplicationStart();
var output = "";
savecontent variable="output" {
request.fw.onRequestEnd();
}
assertTrue( output contains "framework lifecycle trace" );
}

public void function testNoTraceRenderVar() {
variables.fw.onApplicationStart();
variables.fw.renderData( "text", "test" );
var output = "";
savecontent variable="output" {
variables.fw.onRequestEnd();
}
assertFalse( output contains "framework lifecycle trace" );
}

public void function testTraceOutputReq() {
request.fw.onApplicationStart();
variables.fw.renderData( "text", "test" );
var output = "";
savecontent variable="output" {
request.fw.onRequestEnd();
}
assertFalse( output contains "framework lifecycle trace" );
}

}
1 change: 1 addition & 0 deletions tests/frameworkTestSuite.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
testSuite = createObject("component","mxunit.framework.TestSuite").TestSuite();
testSuite.addAll("tests.frameworkPopulateTest");
testSuite.addAll("tests.frameworkErrorTest");
testSuite.addAll("tests.frameworkRenderTest");
testSuite.addAll("tests.frameworkRouteTest");
testSuite.addAll("tests.frameworkResourceRoutesTest");
testSuite.addAll("tests.frameworkProcessRoutesTest");
Expand Down

0 comments on commit 5db30d8

Please sign in to comment.