I'm participating in a project, which extersively uses Presenter pattern.
I don't see a benefits of it, because all the methods of Presenter class are trivial, like this:
class Checkout::NewPresenter
def initialize(customer, order)
@customer, @order = customer, order
end
def customer
@customer
end
def order
@order
end
end
Guys are talking to me, that this pattern makes testing of controllers more simpler. We are abstracted from controller's logic and need just to test presenter object on certain return values.
But, this effect can be achieved with examining instance variables of controller, without any presenter layer.
I've ready Simplifying your Ruby on Rails code: Presenter pattern, cells plugin and agree only with first case:
You have some logic in your view, which uses your models extensively. There are no places in other views with such logic. The classic recommendation is to move this code into a model, but after a short time your models become bloated with stupid one-off helper methods. The solution: pattern Presenter.
I don't understood second case.
Your constructor contains a lot of code to retrieve some values for your views from the database or another storage. You have a lot of fragment_exist? calls to ensure no of your data is loaded when corresponding fragment is already in cache. It’s really hard to test a particular action because of it’s size. The solution: pattern Presenter.
Again, in controllers testing, we are examining only instance variables. What they mean here
The main question is - what benefits has Presenter pattern for controllers testing ?