File tree Expand file tree Collapse file tree 2 files changed +8
-25
lines changed
spec/rspec/rails/matchers Expand file tree Collapse file tree 2 files changed +8
-25
lines changed Original file line number Diff line number Diff line change @@ -230,26 +230,11 @@ def initialize(job)
230
230
def matches? ( proc )
231
231
raise ArgumentError , "have_enqueued_job and enqueue_job only support block expectations" unless Proc === proc
232
232
233
- original_enqueued_jobs_hashes = queue_adapter . enqueued_jobs . map ( &:hash )
234
-
233
+ original_enqueued_jobs = Set . new ( queue_adapter . enqueued_jobs )
235
234
proc . call
235
+ enqueued_jobs = Set . new ( queue_adapter . enqueued_jobs )
236
236
237
- in_block_jobs = queue_adapter . enqueued_jobs . each_with_object ( { } ) do |job , jobs |
238
- jobs [ job . hash ] ||= { job : job , count : 0 }
239
- jobs [ job . hash ] [ :count ] += 1
240
- end
241
-
242
- original_enqueued_jobs_hashes . each do |job_hash |
243
- in_block_jobs [ job_hash ] [ :count ] -= 1 if in_block_jobs . key? ( job_hash )
244
- end
245
-
246
- in_block_jobs = in_block_jobs . each_value . flat_map do |job_and_count |
247
- count , job = job_and_count . values_at ( :count , :job )
248
-
249
- Array . new ( count , job ) if count . positive?
250
- end
251
-
252
- check ( in_block_jobs . compact )
237
+ check ( enqueued_jobs - original_enqueued_jobs )
253
238
end
254
239
255
240
def does_not_match? ( proc )
Original file line number Diff line number Diff line change @@ -101,24 +101,22 @@ def self.name; "LoggingJob"; end
101
101
context "when job is retried" do
102
102
include ActiveJob ::TestHelper
103
103
104
- let ( :retried_job ) do
104
+ let ( :unreliable_job ) do
105
105
Class . new ( ActiveJob ::Base ) do
106
106
retry_on StandardError , wait : 5 , queue : :retry
107
107
108
- def self . name ; "RetriedJob " ; end
108
+ def self . name ; "UnreliableJob " ; end
109
109
def perform ; raise StandardError ; end
110
110
end
111
111
end
112
112
113
- before do
114
- stub_const ( "RetriedJob" , retried_job )
115
- queue_adapter . perform_enqueued_jobs = true
116
- end
113
+ before { stub_const ( "UnreliableJob" , unreliable_job ) }
117
114
118
115
it "passes with reenqueued job" do
119
116
time = Time . current . change ( usec : 0 )
120
117
travel_to time do
121
- expect { retried_job . perform_later } . to have_enqueued_job ( retried_job ) . on_queue ( :retry ) . at ( time + 5 )
118
+ UnreliableJob . perform_later
119
+ expect { perform_enqueued_jobs } . to have_enqueued_job ( UnreliableJob ) . on_queue ( :retry ) . at ( time + 5 )
122
120
end
123
121
end
124
122
end
You can’t perform that action at this time.
0 commit comments