user_info.rb 788 B

12345678910111213141516171819
  1. # This file 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. # If a `:current_user_id` metadata argument is set the initial value for
  9. # UserInfo.current_user_id will be set to the arguments given value
  10. RSpec.configure do |config|
  11. config.before(:each) do |example|
  12. UserInfo.current_user_id = example.metadata[:current_user_id]
  13. end
  14. config.after(:each) do |_example|
  15. UserInfo.current_user_id = nil
  16. end
  17. end