Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/active job test helper #27850

Merged
merged 1 commit into from
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions activejob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Push skipped jobs to `enqueued_jobs` when using `perform_enqueued_jobs` with a `only` filter in tests

*Alexander Pauly*

* Removed deprecated support to passing the adapter class to `.queue_adapter`.

*Rafael Mendonça França*
Expand Down
10 changes: 3 additions & 7 deletions activejob/lib/active_job/queue_adapters/test_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ def performed_jobs
end

def enqueue(job) #:nodoc:
return if filtered?(job)

job_data = job_to_hash(job)
enqueue_or_perform(perform_enqueued_jobs, job, job_data)
end

def enqueue_at(job, timestamp) #:nodoc:
return if filtered?(job)

job_data = job_to_hash(job, at: timestamp)
enqueue_or_perform(perform_enqueued_at_jobs, job, job_data)
end
Expand All @@ -44,11 +40,11 @@ def job_to_hash(job, extras = {})
end

def enqueue_or_perform(perform, job, job_data)
if perform
if !perform || filtered?(job)
enqueued_jobs << job_data
else
performed_jobs << job_data
Base.execute job.serialize
else
enqueued_jobs << job_data
end
end

Expand Down
11 changes: 11 additions & 0 deletions activejob/test/cases/test_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ def test_assert_enqueued_jobs_with_no_block
end
end

def test_assert_enqueued_jobs_when_performing_with_only_option
assert_nothing_raised do
assert_enqueued_jobs 1, only: HelloJob do
perform_enqueued_jobs only: LoggingJob do
HelloJob.perform_later("sean")
LoggingJob.perform_later("yves")
end
end
end
end

def test_assert_no_enqueued_jobs_with_no_block
assert_nothing_raised do
assert_no_enqueued_jobs
Expand Down