Refactoring ruby code #2: Extracting logic to helpers

In this post I want to demonstrate an simple refactoring technique extract method.

Here is an long controller method:



It's obvious that this is not the right place for such logic. So what we do is:
1) Write some tests
2) Create EventsHelper
3) Move all logic from controller to EventsHelper
4) Rewrite test :)

Here is a result:



So, now in views we use previous_moth(@month) instead of @previous_month

What we got:
* Thiner controller
* Separate logic
* Easy testing
* Less variables