jcasimir/draper — Issue #107: Compatibility with other frameworks?
Author: Eleo
Created: 2012-01-04 02:30:51+00:00
State: open

I'm a big fan of Padrino for my projects. The way Padrino does helpers, they are somewhat hard to unit test directly. Controllers/routes/helpers are blocks, and not classes/methods, so it is hard to call a helper method specifically. This was fine for a time, I avoided directly testing helpers in favor of testing proper status code/content type responses in controllers, and used integration tests to make sure the rendered pages contained the proper content. I think this is just fine most of the time, it's appropriately decoupled from the implementation of my controllers and simply ensures the end result is as it should be.

However, as the app size grows, some of the transformations done to a model instance's attributes are non-trivial enough that I want to test it on a more granular level. For example, decorating a Date/Time into a readable string might contain some conditional logic on how that date is displayed (e.g. if the year is the current year, don't display the year). Verifying the integrity of that logic using integration tests is a bit over the top. I can leave such things un-tested, but how do I know a particular logic path doesn't raise an exception?

The decorator pattern seems like a superior approach to many of my view helpers, as decorators are object-oriented and thus very testable. The fact that I can also use it for json/xml responses means I can cut down logic in templates and view helpers, which makes it easier to maintain synchronization between client-side and server-side. Draper itself looks very nice, however, it is advertised as Rails-oriented. Looking at the code, I'm thinking it is nearly abstract enough to work with Padrino, but that is only based on a quick glance. I also want to be sure I am not introducing unnecessary dependencies into my project. Seems like I'd need some additional code to get things working properly. I can get by without generators, but I'd still need to ensure Padrino loaded the decorator classes. That's fine with me, and maybe I can do a something like a padrino-draper gem as glue. I just need some direction.

Any input on this?