ruby on rails 3 - Benefits of Presenter pattern for controller testing -
i'm participating in project, extersively uses presenter pattern.
i don't see benefits of it, because methods of presenter class trivial, this:
class checkout::newpresenter def initialize(customer, order) @customer, @order = customer, order end def customer @customer end def order @order end end
guys talking me, pattern makes testing of controllers more simpler. abstracted controller's logic , need test presenter object on return values.
but, effect can achieved examining instance variables of controller, without presenter layer.
i've ready simplifying ruby on rails code: presenter pattern, cells plugin , agree first case:
you have logic in view, uses models extensively. there no places in other views such logic. classic recommendation move code model, after short time models become bloated stupid one-off helper methods. solution: pattern presenter.
i don't understood second case.
your constructor contains lot of code retrieve values views database or storage. have lot of fragment_exist? calls ensure no of data loaded when corresponding fragment in cache. it’s hard test particular action because of it’s size. solution: pattern presenter.
again, in controllers testing, examining instance variables. mean here
the main question - benefits has presenter pattern controllers testing ?
i have looked @ jay fields presentations on rails presenter pattern found examples useful, haven't looked @ other works third parties around conductors.
to me advantage decouple models, is, total isolation controllers , other models. think better way deal business logic , controller stays thin , knows nothing underlying data storage , structure. however, original rails presenter pattern had 1 problem contained much. presenter object present data should sit between controllers , views that's why conductors should additional interest because sit between models , controllers.
there alternatives out there logical , physical models mentioned in book enterprise rails , full blow domain driven design.
of course, current solution in rails world create methods models manipulate associated models stuffing business login them.
with ddd have seen slides , proposals rails haven't seem full blown implementation hope gem generators become available in not distant future. ddd useful option complex projects, not alternative method of design , rails meant flexible allowing drop in code , modular expansion don't see dropping layers , class types mix issue. rails purists may hate idea needn't use it.
Comments
Post a Comment