DEV Community

Discussion on: The 10-minute Rails Pub/Sub

abahaggag profile image
Ahmed Ba Haggag

Thanks for sharing. I have a concern now, suppose I have a test cases and I don't want to run these callbacks so is it possible to stop them while testing?

Actually I used to use callbacks a lot but not anymore bacause it's difficult to debug and maintain in case you have a lot of them. So my suggestion is creating new interactor class for creating user CreateUserInteractor and will add all logic there and in case I have complex logic then will add a separate class for each process which will be called in CreateUserInteractor.

What do you think?

zorbash profile image
Dimitris Zorbas Author

Structuring your event subscriptions in interactor classes sounds good. To skip event subscriber calls in your tests you can use regular stubs.

For example allow(UserSubscriber).to receive(:subscribe) would do the trick.