Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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