Refactors PostsController and adds unit tests.

removes some duplication (minimally reduces Code Climate complexity) and adds missing unit tests to support the refactoring