2018-03-28 05:33:41 +00:00
|
|
|
# This module registers a before and after each hook callback that
|
|
|
|
# resets the stored current_user_id in the UserInfo which will otherwise
|
|
|
|
# persists across multiple examples.
|
|
|
|
# This can lead to issues where actions were performed by a user created
|
|
|
|
# via a FactoryBot factory which will get removed after the example is
|
|
|
|
# completed. The UserInfo.current_user_id will persist which leads to e.g.
|
|
|
|
# DB ForeignKey violation errors.
|
|
|
|
module ZammadSpecSupportUserInfo
|
|
|
|
|
|
|
|
def self.included(base)
|
|
|
|
|
|
|
|
# Execute in RSpec class context
|
|
|
|
base.class_exec do
|
|
|
|
|
|
|
|
before(:each) do |_example|
|
|
|
|
UserInfo.current_user_id = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:each) do |_example|
|
|
|
|
UserInfo.current_user_id = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.include ZammadSpecSupportUserInfo
|
2019-03-13 23:51:22 +00:00
|
|
|
|
|
|
|
config.around(:each, :current_user_id) do |example|
|
|
|
|
UserInfo.current_user_id = example.metadata[:current_user_id]
|
|
|
|
begin
|
|
|
|
example.run
|
|
|
|
ensure
|
|
|
|
UserInfo.current_user_id = nil
|
|
|
|
end
|
|
|
|
end
|
2018-03-28 05:33:41 +00:00
|
|
|
end
|