From f345e828dd04bdfb929eedde0a3e2790dd5bbfa3 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Sat, 28 Mar 2020 09:15:47 +0000 Subject: [PATCH] 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 --- lib/rspec/rails/matchers/active_job.rb | 8 ++++++-- spec/rspec/rails/matchers/active_job_spec.rb | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/rspec/rails/matchers/active_job.rb b/lib/rspec/rails/matchers/active_job.rb index 88f81f0ffc..1a7be83132 100644 --- a/lib/rspec/rails/matchers/active_job.rb +++ b/lib/rspec/rails/matchers/active_job.rb @@ -30,8 +30,12 @@ def on_queue(queue) self end - def at(date) - @at = date + def at(time_or_date) + case time_or_date + when Time then @at = Time.at(time_or_date.to_f) + else + @at = time_or_date + end self end diff --git a/spec/rspec/rails/matchers/active_job_spec.rb b/spec/rspec/rails/matchers/active_job_spec.rb index 06ff55e23e..d9cd4b8e89 100644 --- a/spec/rspec/rails/matchers/active_job_spec.rb +++ b/spec/rspec/rails/matchers/active_job_spec.rb @@ -216,6 +216,13 @@ def self.name; "LoggingJob"; end }.to have_enqueued_job.at(date) end + it "passes with provided at time" do + time = Time.now + 1.day + expect { + hello_job.set(wait_until: time).perform_later + }.to have_enqueued_job.at(time) + end + it "accepts composable matchers as an at date" do future = 1.minute.from_now slightly_earlier = 58.seconds.from_now