Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is an example of how I combine interaction/service classes with Wisper event broadcasting in Rails.
- In this example, I show a `UsersController#create` API, a corresponding service object, and all the test code/listeners to make it all happen.
- The outcome is:
- * 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.
- * Since your concept has one entry point (the service class), you can easily `grep` for usage of it.
- * Stupid easy to attach listeners to the service class
- * All event listeners are very small and easily unit tested
- * Controllers have zero `if/else` logic and are very stupid
- * Unit tests stay fast
- * Acceptance tests still exercise the whole system, including event listeners
- * Plain old Ruby objects rule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement