aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGannon McGibbon <gannon.mcgibbon@gmail.com>2019-03-25 01:33:53 -0400
committerGannon McGibbon <gannon.mcgibbon@gmail.com>2019-03-25 01:37:42 -0400
commit39b6840f3c8ea026dae7c4f6c156afabedcefd00 (patch)
tree04b656003e1c3da6265e9db77b5e688cd90ccec9
parentdbd1db91d9c23c69614940d64fadba78bf925f50 (diff)
downloadrails-39b6840f3c8ea026dae7c4f6c156afabedcefd00.tar.gz
rails-39b6840f3c8ea026dae7c4f6c156afabedcefd00.tar.bz2
rails-39b6840f3c8ea026dae7c4f6c156afabedcefd00.zip
Add section on asserting time args for jobs
-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 93372b5c26..04f0297480 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
--------------------