Skip to content

Commit

Permalink
Merge pull request #2780 from rspec/improve-active-job-matcher
Browse files Browse the repository at this point in the history
Refactor active job matcher
  • Loading branch information
JonRowe authored Aug 13, 2024
2 parents 6f9977f + 524a159 commit 512cc0a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/rspec/rails/matchers/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def supports_block_expectations?

def check(jobs)
@matching_jobs, @unmatching_jobs = jobs.partition do |job|
if job_match?(job) && arguments_match?(job) && queue_match?(job) && at_match?(job) && priority_match?(job)
if matches_constraints?(job)
args = deserialize_arguments(job)
@block.call(*args)
true
Expand All @@ -123,10 +123,6 @@ def check(jobs)
return false
end

check_countable
end

def check_countable
@matching_jobs_count = @matching_jobs.size

case @expectation_type
Expand Down Expand Up @@ -163,13 +159,23 @@ def base_job_message(job)
end
end

def job_match?(job)
def matches_constraints?(job)
job_matches?(job) && arguments_match?(job) && queue_match?(job) && at_match?(job) && priority_match?(job)
end

def job_matches?(job)
@job ? @job == job[:job] : true
end

# Rails 6.1 serializes the priority with a string key
def fetch_priority(job)
job[:priority] || job['priority']
if ::Rails.version.to_f >= 7
def fetch_priority(job)
job[:priority]
end
else
def fetch_priority(job)
job['priority']
end
end

def arguments_match?(job)
Expand Down

0 comments on commit 512cc0a

Please sign in to comment.