7
7
module RSpec
8
8
module Rails
9
9
module Matchers
10
- # rubocop: disable Metrics/ClassLength
11
10
# Matcher class for `have_enqueued_mail`. Should not be instantiated directly.
12
11
#
13
12
# @private
@@ -91,7 +90,7 @@ def arguments_match?(job)
91
90
92
91
def process_arguments ( job , given_mail_args )
93
92
# Old matcher behavior working with all builtin classes but ActionMailer::MailDeliveryJob
94
- return given_mail_args unless defined? ( ActionMailer :: MailDeliveryJob ) && job [ :job ] <= ActionMailer :: MailDeliveryJob
93
+ return given_mail_args if use_given_mail_args? ( job )
95
94
96
95
# If matching args starts with a hash and job instance has params match with them
97
96
if given_mail_args . first . is_a? ( Hash ) && job [ :args ] [ 3 ] [ 'params' ] . present?
@@ -101,6 +100,13 @@ def process_arguments(job, given_mail_args)
101
100
end
102
101
end
103
102
103
+ def use_given_mail_args? ( job )
104
+ return true if FeatureCheck . has_action_mailer_parameterized? && job [ :job ] <= ActionMailer ::Parameterized ::DeliveryJob
105
+ return false if FeatureCheck . ruby_3_1?
106
+
107
+ !( FeatureCheck . has_action_mailer_unified_delivery? && job [ :job ] <= ActionMailer ::MailDeliveryJob )
108
+ end
109
+
104
110
def base_mailer_args
105
111
[ mailer_class_name , @method_name . to_s , MAILER_JOB_METHOD ]
106
112
end
@@ -143,13 +149,20 @@ def mail_job_message(job)
143
149
mailer_args = deserialize_arguments ( job ) [ 3 ..-1 ]
144
150
mailer_args = mailer_args . first [ :args ] if unified_mail? ( job )
145
151
msg_parts = [ ]
146
- msg_parts << "with #{ mailer_args } " if mailer_args . any?
152
+ display_args = display_mailer_args ( mailer_args )
153
+ msg_parts << "with #{ display_args } " if display_args . any?
147
154
msg_parts << "on queue #{ job [ :queue ] } " if job [ :queue ] && job [ :queue ] != 'mailers'
148
155
msg_parts << "at #{ Time . at ( job [ :at ] ) } " if job [ :at ]
149
156
150
157
"#{ mailer_method } #{ msg_parts . join ( ', ' ) } " . strip
151
158
end
152
159
160
+ def display_mailer_args ( mailer_args )
161
+ return mailer_args unless mailer_args . first . is_a? ( Hash ) && mailer_args . first . key? ( :args )
162
+
163
+ mailer_args . first [ :args ]
164
+ end
165
+
153
166
def legacy_mail? ( job )
154
167
RSpec ::Rails ::FeatureCheck . has_action_mailer_legacy_delivery_job? && job [ :job ] <= ActionMailer ::DeliveryJob
155
168
end
@@ -162,7 +175,6 @@ def unified_mail?(job)
162
175
RSpec ::Rails ::FeatureCheck . has_action_mailer_unified_delivery? && job [ :job ] <= ActionMailer ::MailDeliveryJob
163
176
end
164
177
end
165
- # rubocop: enable Metrics/ClassLength
166
178
167
179
# @api public
168
180
# Passes if an email has been enqueued inside block.
0 commit comments