1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add List The Enqueued Jobs as a rails til

This commit is contained in:
jbranchaud
2016-12-21 20:41:33 -06:00
parent a7e5b1d8f0
commit 56358fe6ad
2 changed files with 35 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
warrant a full blog post. These are mostly things I learn by pairing with
smart people at [Hashrocket](http://hashrocket.com/).
_491 TILs and counting..._
_492 TILs and counting..._
---
@@ -316,6 +316,7 @@ _491 TILs and counting..._
- [Demodulize A Class Name](rails/demodulize-a-class-name.md)
- [Hash Slicing](rails/hash-slicing.md)
- [Ignore Poltergeist JavaScript Errors](rails/ignore-poltergeist-javascript-errors.md)
- [List The Enqueued Jobs](rails/list-the-enqueued-jobs.md)
- [Migrating Up Down Up](rails/migrating-up-down-up.md)
- [Params Includes Submission Button Info](rails/params-includes-submission-button-info.md)
- [Perform SQL Explain With ActiveRecord](rails/perform-sql-explain-with-activerecord.md)

View File

@@ -0,0 +1,33 @@
# List The Enqueued Jobs
Many Rails apps need to delegate work to jobs that can be performed at a
later time. Both unit and integration testing can benefit from asserting
about the jobs that get enqueued as part of certain methods and workflows.
Rails provides a handy helper method for checking out the set of enqueued
jobs at any given time.
The
[`enqueued_jobs`](http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/TestAdapter.html#method-i-enqueued_jobs)
method will provide a store of all the currently enqueued jobs.
It provides a number of pieces of information about each job. One way to
use the information is like so:
```ruby
describe '#do_thing' do
it 'enqueues a job to do a thing later' do
Processor.do_thing(arg1, arg2)
expect(enqueued_jobs.map { |job| job[:job] }).to match_array([
LongProcessJob,
SendEmailsJob
])
end
end
```
To use this in your Rails project, just enable the adapter in your test
configuration file:
```ruby
Rails.application.config.active_job.queue_adapter = :test
```