[coldbox-3.5.0-BE] requestStartHandler versus "eventual" handler

I’m sure this has been answered before - and I searched the forum but to be honest I don’t know the terms to search for!

TL:DR -> I’m running a test against Something/index but event.getCollection() only contains rc vars from the requestStartHandler

start / test function body ----

var event = “”;
event = execute(“Something/index”);

debug(event.getCollection());

end / test function body ----

The index method in the Something handler sets some variables into the rc scope (shhhh I’m writing the test after I’ve written the actual code)
But all I see in the debug call above is variables set into the rc scope from the requestStartHandler -> Main.index

start / Main.index function body----

rc.loggedInUser = securityService.getUserSession();
rc.adminRole = roleService.findWhere(criteria={name=“admin”});
rc.blah = {“now” = now()};
if(!isNull(rc.loggedInUser))
{
rc.loggedInUserIsAdmin = rc.loggedInUser.hasRole(rc.adminRole);
}

end / Main.index function body----

So all I’m seeing are rc.loggedInUser, rc.adminRole etc

What am I missing?

Thanks in advance
Steve

I created a new “Advanced” app and this did not occur. So it must be something to do with the solitary module.
sigh.

has no one seen this behaviour before?

time to start ripping things out until it works.
on the bright side at least I’ve got a test to run after I remove each thing.

OK I am confused now.

Completely removed the solitary module and yet:

ANY variable that is set in the Handler I’m testing doesn’t get set

ONLY variables in the handler defined as requestStartHandler are being set?

what the hell is going on??

Of course this behaviour IS NOT happening in the main app - only via the test

so a question for coldbox/mxunit-ers … what could I be doing in my test/Application.cfc that would cause this? I presume that is the only place this config change could be occurring?

Are you doing unit tests or integration tests?

I’m trying to do an integration test - well in my mind that is what I am doing.

I’m trying to test that a Handler, when called, populates the request with the right variables.

  • it already is doing this correctly via the browser -

I’ve ripped out everything I can think of and it’s like it’s not even firing the event I execute in the test.

(btw - appreciate the help)

OK - I’m reeking of desperation I know.

I’ve removed all my handlers, views and tests and am adding them back in little by little (tests first!)

I hit a similar (s i m i l a r) issue when I add “GET” to the allowedMethods for the index key in the handler. Could this have been my issue? ie. mxunit somehow isn’t doing a GET that coldbox recognises?

I don’t know enough about the internals of coldbox to answer that BUT it fails when ONLY GET is there, but passes when POST is added.

anyone?

Well that was definitely the problem.

My handler method was (correctly) setup to only allow HTTP GET access.
Obviously mxunit must use POST under the covers (I haven’t busted out a HTTP sniffer to confirm this) and so the call to the action was being silently lost.

Seeding this post with the keywords for the next poor sap that runs into this issue won’t help. sigh.

Stephen,

Have you asked about this on the mxUnit mailing list?

Sounds like something that they might need to add, now that ColdFusion 10 has introduced RESTful calls as well.

Yes the web service call in mxunit uses post. Mock the http method in the request context as well

Getmockbox().preparemock( getrequestcontext() ).$(“gethttpmethod”,“get”)

I wouldn’t know where to start to be honest…

Thanks Luis - that is a very elegant solution.

(updated: didn’t the old google groups scrub email addresses in the body automatically?)