Skip to content

Commit

Permalink
[TAN-3184] Wrap tests in Rails executor when configured
Browse files Browse the repository at this point in the history
  • Loading branch information
adessy committed Dec 20, 2024
1 parent c87030f commit e90c7c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
25 changes: 13 additions & 12 deletions back/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,19 @@
config.include StubEnvHelper
config.include XlsxHelper

# If we do not include the following module, the controller tests do not reset the
# `CurrentAttributes` before and after each test.
# Per: https://bytemeta.vip/repo/rspec/rspec-rails/issues/2503, rspec-rails should in
# theory load the helpers automatically, but for some reason this does not seem to
# work.
# > If you add type: :model the problem should similarly go away, we don't include
# > rails helpers except when running a rails test, so currently you'd need to pick
# > one of the rails types.
#
# As a quick fix, we import the module explicitly. A tech-debt ticket has been logged
# here: https://citizenlab.atlassian.net/browse/CL-1860
config.include ActiveSupport::CurrentAttributes::TestHelper, type: :controller
# rspec-rails do not take the `executor_around_test_case` option into account. There is
# an open issue for this: https://github.com/rspec/rspec-rails/pull/2753.
# Here, we replicate the behavior used by Rails for `ActiveSupport::TestCase`.
# See: https://github.com/rails/rails/blob/8278626a2c0e0ee4dc762891a91e70708380b4d6/activesupport/lib/active_support/railtie.rb#L52-L63
if Rails.application.config.active_support.executor_around_test_case
config.include ExecutorTestHelper
else
require 'active_support/current_attributes/test_helper'
config.include ActiveSupport::CurrentAttributes::TestHelper

require 'active_support/execution_context/test_helper'
config.include ActiveSupport::ExecutionContext::TestHelper
end
end

ActiveJob::Base.queue_adapter = :test
9 changes: 9 additions & 0 deletions back/spec/support/executor_test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module ExecutorTestHelper
def self.included(base)
base.around do |example|
Rails.application.executor.perform { example.run }
end
end
end

0 comments on commit e90c7c2

Please sign in to comment.