Skip to content

Commit 512cc0a

Browse files
authored
Merge pull request #2780 from rspec/improve-active-job-matcher
Refactor active job matcher
2 parents 6f9977f + 524a159 commit 512cc0a

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/rspec/rails/matchers/active_job.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def supports_block_expectations?
109109

110110
def check(jobs)
111111
@matching_jobs, @unmatching_jobs = jobs.partition do |job|
112-
if job_match?(job) && arguments_match?(job) && queue_match?(job) && at_match?(job) && priority_match?(job)
112+
if matches_constraints?(job)
113113
args = deserialize_arguments(job)
114114
@block.call(*args)
115115
true
@@ -123,10 +123,6 @@ def check(jobs)
123123
return false
124124
end
125125

126-
check_countable
127-
end
128-
129-
def check_countable
130126
@matching_jobs_count = @matching_jobs.size
131127

132128
case @expectation_type
@@ -163,13 +159,23 @@ def base_job_message(job)
163159
end
164160
end
165161

166-
def job_match?(job)
162+
def matches_constraints?(job)
163+
job_matches?(job) && arguments_match?(job) && queue_match?(job) && at_match?(job) && priority_match?(job)
164+
end
165+
166+
def job_matches?(job)
167167
@job ? @job == job[:job] : true
168168
end
169169

170170
# Rails 6.1 serializes the priority with a string key
171-
def fetch_priority(job)
172-
job[:priority] || job['priority']
171+
if ::Rails.version.to_f >= 7
172+
def fetch_priority(job)
173+
job[:priority]
174+
end
175+
else
176+
def fetch_priority(job)
177+
job['priority']
178+
end
173179
end
174180

175181
def arguments_match?(job)

0 commit comments

Comments
 (0)