Skip to content

Commit 9c9eb39

Browse files
Tweak requires in preview app, initial pass at 2 Ruby 3.1 / Rails 6.1 fixes
1 parent 0e15994 commit 9c9eb39

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

example_app_generator/spec/support/default_preview_path

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ require_file_stub 'config/environment' do
2626
require "action_controller/railtie"
2727
require "action_mailer/railtie" unless ENV['NO_ACTION_MAILER']
2828
require "action_view/railtie"
29-
require "action_cable/engine" if Rails::VERSION::STRING >= '6'
29+
if Rails::VERSION::STRING >= '6'
30+
require "action_cable/engine"
31+
require 'action_mailbox/engine'
32+
end
3033

3134
# Require the gems listed in Gemfile, including any gems
3235
# you've limited to :test, :development, or :production.
@@ -45,6 +48,8 @@ require_file_stub 'config/environment' do
4548
if ENV['SHOW_PREVIEWS']
4649
config.action_mailer.show_previews = (ENV['SHOW_PREVIEWS'] == 'true')
4750
end
51+
52+
config.active_record.legacy_connection_handling = false if Rails::VERSION::STRING >= '7'
4853
end
4954
end
5055

example_app_generator/spec/verify_mailer_preview_path_spec.rb

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def capture_exec(*ops)
2222
out = io.readlines
2323
.reject { |line| line =~ /warning: circular argument reference/ }
2424
.reject { |line| line =~ /Gem::Specification#rubyforge_project=/ }
25+
.reject { |line| line =~ /DEPRECATION WARNING/ }
26+
.reject { |line| line =~ /warning: previous/ }
27+
.reject { |line| line =~ /warning: already/ }
2528
.join
2629
.chomp
2730
CaptureExec.new(out, $?.exitstatus)

lib/rspec/rails/matchers/have_enqueued_mail.rb

+22-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def arguments_match?(job)
9191

9292
def process_arguments(job, given_mail_args)
9393
# Old matcher behavior working with all builtin classes but ActionMailer::MailDeliveryJob
94-
return given_mail_args unless defined?(ActionMailer::MailDeliveryJob) && job[:job] <= ActionMailer::MailDeliveryJob
94+
return given_mail_args if use_given_mail_args?(job)
9595

9696
# If matching args starts with a hash and job instance has params match with them
9797
if given_mail_args.first.is_a?(Hash) && job[:args][3]['params'].present?
@@ -101,6 +101,19 @@ def process_arguments(job, given_mail_args)
101101
end
102102
end
103103

104+
def use_given_mail_args?(job)
105+
return false if rails_6_1_and_ruby_3_1?
106+
107+
!(defined?(ActionMailer::MailDeliveryJob) && job[:job] <= ActionMailer::MailDeliveryJob)
108+
end
109+
110+
def rails_6_1_and_ruby_3_1?
111+
return false unless RUBY_VERSION >= "3.1"
112+
return false unless ::Rails::VERSION::STRING >= '6.1'
113+
114+
::Rails::VERSION::STRING < '7'
115+
end
116+
104117
def base_mailer_args
105118
[mailer_class_name, @method_name.to_s, MAILER_JOB_METHOD]
106119
end
@@ -143,13 +156,20 @@ def mail_job_message(job)
143156
mailer_args = deserialize_arguments(job)[3..-1]
144157
mailer_args = mailer_args.first[:args] if unified_mail?(job)
145158
msg_parts = []
146-
msg_parts << "with #{mailer_args}" if mailer_args.any?
159+
display_args = display_mailer_args(mailer_args)
160+
msg_parts << "with #{display_args}" if display_args.any?
147161
msg_parts << "on queue #{job[:queue]}" if job[:queue] && job[:queue] != 'mailers'
148162
msg_parts << "at #{Time.at(job[:at])}" if job[:at]
149163

150164
"#{mailer_method} #{msg_parts.join(', ')}".strip
151165
end
152166

167+
def display_mailer_args(mailer_args)
168+
return mailer_args unless mailer_args.first.is_a?(Hash) && mailer_args.first.key?(:args)
169+
170+
mailer_args.first[:args]
171+
end
172+
153173
def legacy_mail?(job)
154174
RSpec::Rails::FeatureCheck.has_action_mailer_legacy_delivery_job? && job[:job] <= ActionMailer::DeliveryJob
155175
end

0 commit comments

Comments
 (0)