Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. This is an example of how I combine interaction/service classes with Wisper event broadcasting in Rails.
  2.  
  3. In this example, I show a `UsersController#create` API, a corresponding service object, and all the test code/listeners to make it all happen.
  4.  
  5. The outcome is:
  6.  
  7. * Concepts in your system ("Signing up a user", "Creating an order") have a single entry point in your codebase, vs. making stupid raw ActiveRecord calls to `object.save` in dozens of places.
  8. * Since your concept has one entry point (the service class), you can easily `grep` for usage of it.
  9. * Stupid easy to attach listeners to the service class
  10. * All event listeners are very small and easily unit tested
  11. * Controllers have zero `if/else` logic and are very stupid
  12. * Unit tests stay fast
  13. * Acceptance tests still exercise the whole system, including event listeners
  14. * Plain old Ruby objects rule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement