Skip to content

Commit f345e82

Browse files
JonRowedoits
andcommitted
Fix comparison of times for #at in job matchers.
Prior to 4.0.0 we used `to_f` to ensure parity of precision with Rails internals this was lost when we added support for date matching, but this restores it for Time objects only. Co-authored-by: Markus Doits <[email protected]>
1 parent bef9822 commit f345e82

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/rspec/rails/matchers/active_job.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ def on_queue(queue)
3030
self
3131
end
3232

33-
def at(date)
34-
@at = date
33+
def at(time_or_date)
34+
case time_or_date
35+
when Time then @at = Time.at(time_or_date.to_f)
36+
else
37+
@at = time_or_date
38+
end
3539
self
3640
end
3741

spec/rspec/rails/matchers/active_job_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ def self.name; "LoggingJob"; end
216216
}.to have_enqueued_job.at(date)
217217
end
218218

219+
it "passes with provided at time" do
220+
time = Time.now + 1.day
221+
expect {
222+
hello_job.set(wait_until: time).perform_later
223+
}.to have_enqueued_job.at(time)
224+
end
225+
219226
it "accepts composable matchers as an at date" do
220227
future = 1.minute.from_now
221228
slightly_earlier = 58.seconds.from_now

0 commit comments

Comments
 (0)