Skip to content

Commit

Permalink
fix: mailer specs for Rails 8- and 8+
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Apr 26, 2024
1 parent 7d0dbc0 commit 0c28ebd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
15 changes: 3 additions & 12 deletions spec/isolator/adapters/background_jobs/active_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
expect { ActiveJobWorker.perform_later("test") }.to raise_error(Isolator::BackgroundJobError, /ActiveJobWorker.+test/)
end

context "with enqueue_after_transaction_commit", :rails72 do
context "with enqueue_after_transaction_commit", :rails8 do
after { reset_enqueue_after_transaction_commit }

context "configured to :always" do
Expand Down Expand Up @@ -73,20 +73,11 @@
private

def set_enqueue_after_transaction_commit_to(value)
Rails.application.config.active_job.enqueue_after_transaction_commit = value
run_enqueue_after_transaction_commit_initializer
ActiveJobWorker.enqueue_after_transaction_commit = value # manually (re)set for subclass
ActiveJob::Base.enqueue_after_transaction_commit = value
end

def reset_enqueue_after_transaction_commit
Rails.application.config.active_job.enqueue_after_transaction_commit = :default
run_enqueue_after_transaction_commit_initializer
ActiveJobWorker.enqueue_after_transaction_commit = :default # manually (re)set for subclass
allow(ActiveJob::Base.queue_adapter).to receive(:enqueue_after_transaction_commit?) { true }
end

def run_enqueue_after_transaction_commit_initializer
Rails.application.initializers.find { |i| i.name == "active_job.enqueue_after_transaction_commit" }.run
ActiveJob::Base.enqueue_after_transaction_commit = :never
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
RSpec.configure do |config|
config.example_status_persistence_file_path = ".rspec_status"
config.filter_run focus: true
# TODO: replace with `Rails.version >= Gem::Version.new("7.2")` once 7.2 is released
unless Rails::VERSION::MAJOR >= 7 && Rails::VERSION::MINOR >= 2
config.filter_run_excluding :rails72
# TODO: remove first condition once 8.0 is released
if (Rails::VERSION::MAJOR >= 7 && Rails::VERSION::MINOR >= 2) || (Rails::VERSION::MAJOR >= 8)
config.filter_run_excluding :rails_pre_8
else
config.filter_run_excluding :rails8
end
config.run_all_when_everything_filtered = true

Expand Down
4 changes: 4 additions & 0 deletions spec/support/active_job_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@

ActiveJob::Base.queue_adapter = :test
ActiveJob::Base.logger = Logger.new(IO::NULL)
# disable transactional commits by default
if ActiveJob::Base.respond_to?(:enqueue_after_transaction_commit=)
ActiveJob::Base.enqueue_after_transaction_commit = :never
end

0 comments on commit 0c28ebd

Please sign in to comment.