Refactors PostsController and adds unit tests.
Merge pull request #1971 from velesin/posts_controller_refactoring

Refactors PostsController and adds unit tests.