Having just written a series of integration and functional tests in a hurry in some cases before implementing a controller action and some hastily afterwards... I find myself wanting to be more explicit about the parameters that are getting passed back and forth between server and client.
Afaict, most things being sent between server and browser are name/value pairs: http headers incl session/cookies; form/url/ajax parameters. My thought was this: wouldn't it be nice not to have to create X number of controller files with Y number of actions in each with bespoke code doing pretty much the same sorts of things each time. Instead, wouldn't it be nice to be able to specify up front which urls you want to expose (/path/to/action) along with their http method(s) and then against each such resource, define what parameters (name/value pairs) are required and what actions will get performed once those requirements are met (as well as what to do if they're not). You then feed this specification into a state machine type application (maybe built from ragel) and you're pretty much done. I've dubbed the idea "ParamsMachine" (PM). PM just sits behind rack or something and gets fed the incoming request: first the url including the format (.xml etc), then the http method; then any headers, session, cookie name value pairs; finally the remaining name value pairs as defined by the parameters from the url or the form. PM can fail if invalid information is fed into it; you could have a strict mode that disallows any extra parameters from being sent for instance and a permissive mode that just ignores the extra junk. If an invalid url or http method is sent it would obviously fail with a status of not found or 500 application error. Because you've prebuilt it as a state machine on a solid implementation such as ragel, you know and can specify exactly what can happen. PM will of course pass off the parameters to the models or the next level once it has validated. If the model blows up, then this error is handled by PM as well. After you've loaded PM you can get it to check your views to make sure that any forms or anchor tags use the required number of parameters for the url they are accessing. It would be as simple as mining all the action and href attributes and feeding them and any related info into PM so that PM can check that they are sending the required stuff. Might have to be done at an integration test level to include cookies and sessions. It might be possible to have a form and link helpers that build a form/link for a given action and fails if you don't handle all the required parameters or use ones that aren't valid. The big motivator for me would be having a file or series of files that specify exactly what the resources are and what parameters they expect rather than leaving it as implied via a hodge podge of controller and view code. Crazy? Already done? Daniel -- Daniel Bush --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en -~----------~----~----~----~------~----~------~--~---
