Guest User

Untitled

a guest
May 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. def assert_worker_runs_methods(worker, *methods)
  2. worker_klass = "#{worker.to_s.camelize}Worker".constantize
  3. methods.each do |method|
  4. worker_klass.any_instance.stubs(method).returns(true)
  5. MiddleMan.expects(:worker).with(:"#{worker}_worker").returns(worker_klass.new)
  6. end
  7. end
  8.  
  9. def deny_worker_runs_methods(worker, *methods)
  10. worker_klass = "#{worker.to_s.camelize}Worker".constantize
  11. methods.each do |method|
  12. worker_klass.any_instance.stubs(method).returns(true)
  13. MiddleMan.expects(:worker).with(:"#{worker}_worker").returns(worker_klass.new).never
  14. end
  15. end
  16.  
  17. # Shoulda examples
  18. should "update cached csv registration after save" do
  19. assert_worker_runs_methods :form_updater, :async_update_cached_csv_registrations
  20. assert forms(:one).save
  21. end
  22.  
  23. should "not update cached csv registration after update if event has no registrations" do
  24. Registration.delete_all
  25. deny_worker_runs_methods :form_updater, :async_update_cached_csv_registrations
  26. assert forms(:one).save
  27. end
Add Comment
Please, Sign In to add comment