user_info.rb 812 B

12345678910111213141516171819202122232425262728
  1. # This module registers a before and after each hook callback that
  2. # resets the stored current_user_id in the UserInfo which will otherwise
  3. # persists across multiple examples.
  4. # This can lead to issues where actions were performed by a user created
  5. # via a FactoryBot factory which will get removed after the example is
  6. # completed. The UserInfo.current_user_id will persist which leads to e.g.
  7. # DB ForeignKey violation errors.
  8. module ZammadSpecSupportUserInfo
  9. def self.included(base)
  10. # Execute in RSpec class context
  11. base.class_exec do
  12. before(:each) do |_example|
  13. UserInfo.current_user_id = nil
  14. end
  15. after(:each) do |_example|
  16. UserInfo.current_user_id = nil
  17. end
  18. end
  19. end
  20. end
  21. RSpec.configure do |config|
  22. config.include ZammadSpecSupportUserInfo
  23. end