Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Earlier Draft: Single purpose controller #7

Open
wants to merge 2 commits into
base: fat_controller_method_setup
Choose a base branch
from

Conversation

justin808
Copy link
Member

Single Purpose Controller

This is a preferable alternative to pull request #6, which uses a Service Object pattern.

Objectives:

  • Splitting the MicropostController into the MicropostCreateController to so
    that a complicated controller method can be refactored to have many private
    methods that relate to the only public method, on the "single purpose
    controller". I.e. conform to the Sandi rules of small methods.
  • Demonstrate changing the routing for a custom named controller.
  • Demonstrate a controller spec that covers everything the service object spec
    covered, but covers it more accurately because it actually verifies that the
    controller is doing the right thing.
  • Demonstrate following features of controller spec testing in rspec:
  • testing flash.now
  • checking instance variable
  • checking rendered template
  • Demonstrate using a model object, ProfanityChecker to handle logic for a
    potentially complex validation.
  • Demonstrates simple tests of this ProfanityChecker class.

Review on Reviewable

* ProfanityChecker encapsulates logic of checking for profanity.
* Simple to test this way.
* Moved large method create into own controller class.
* Refactored large method into numerous small private methods.
* Adjusted routes for change in controllers
* Created controller spec that verifies
  * flash messages set correctly
  * redirect or rendering done
@gylaz
Copy link

gylaz commented Apr 12, 2014

Might be worth taking a look at focused_controller gem.

@justin808
Copy link
Member Author

@gylaz I've seen it, but have not tried it. Any experience with it on real projects? Any distinct advantage over basic rails constructs of distinct controllers and using concerns for the common elements.

@gylaz
Copy link

gylaz commented Apr 12, 2014

I have not used it (or know of anyone that has). I remember reading about it a while back, and your proposal stirred that memory. Here's a blog post from the creator of that gem.

@justin808 justin808 changed the title Single purpose controller Earlier Draft: Single purpose controller Apr 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants