aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorGannon McGibbon <gannon.mcgibbon@gmail.com>2019-04-20 12:36:58 +0900
committerGitHub <noreply@github.com>2019-04-20 12:36:58 +0900
commit9057e64151428143cf182b115829d3cd6a0e94ff (patch)
treef7957322fe25074ea5bfc90b5bf1af2ce873bb8e /guides
parent21747560be42d68200060a1d90419717e0ca339e (diff)
parent39b6840f3c8ea026dae7c4f6c156afabedcefd00 (diff)
downloadrails-9057e64151428143cf182b115829d3cd6a0e94ff.tar.gz
rails-9057e64151428143cf182b115829d3cd6a0e94ff.tar.bz2
rails-9057e64151428143cf182b115829d3cd6a0e94ff.zip
Merge pull request #35738 from gmcgibbon/aj_assert_drop_usec_docs
ActiveJob time argument assertion documentation
Diffstat (limited to 'guides')
-rw-r--r--guides/source/testing.md19
1 files changed, 19 insertions, 0 deletions
diff --git a/guides/source/testing.md b/guides/source/testing.md
index 1fad02812b..26448958ea 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -1733,6 +1733,25 @@ class ProductTest < ActiveSupport::TestCase
end
```
+### Asserting Time Arguments in Jobs
+
+When serializing job arguments, `Time`, `DateTime`, and `ActiveSupport::TimeWithZone` lose microsecond precision. This means comparing deserialized time with actual time doesn't always work. To compensate for the loss of precision, `assert_enqueued_with` and `assert_performed_with` will remove microseconds from time objects in argument assertions.
+
+```ruby
+require 'test_helper'
+
+class ProductTest < ActiveSupport::TestCase
+ include ActiveJob::TestHelper
+
+ test 'that product is reserved at a given time' do
+ now = Time.now
+ assert_performed_with(job: ReservationJob, args: [product, now]) do
+ product.reserve(now)
+ end
+ end
+end
+```
+
Testing Action Cable
--------------------