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

Add an `:only` option to `perform_enqueued_jobs` to filter jobs based on type. #18833

Merged
merged 1 commit into from Feb 6, 2015

Conversation

@perceptec
Copy link
Contributor

perceptec commented Feb 6, 2015

This allows specific jobs to be tested, while preventing others from being performed unnecessarily. An array may also be specified, to support testing multiple jobs.

Fixes #18802.

@rafaelfranca
rafaelfranca reviewed Feb 6, 2015
View changes
activejob/lib/active_job/test_helper.rb Outdated
@@ -125,10 +125,10 @@ def assert_no_enqueued_jobs(only: nil, &block)
# HelloJob.perform_later('sean')
# end
# end
def assert_performed_jobs(number)
def assert_performed_jobs(number, only: nil)

This comment has been minimized.

Copy link
@rafaelfranca

rafaelfranca Feb 6, 2015

Member

Could you document this new option here?

@rafaelfranca
rafaelfranca reviewed Feb 6, 2015
View changes
activejob/test/cases/test_helper_test.rb Outdated
assert_match(/0 .* but 1/, error.message)
end


This comment has been minimized.

Copy link
@rafaelfranca

rafaelfranca Feb 6, 2015

Member

✂️ this blank line

@rafaelfranca
rafaelfranca reviewed Feb 6, 2015
View changes
activejob/lib/active_job/queue_adapters/test_adapter.rb Outdated
def filtered?(job)
filter && !Array(filter).include?(job.class)
end

This comment has been minimized.

Copy link
@rafaelfranca

rafaelfranca Feb 6, 2015

Member

✂️ this blank line

type.

This allows specific jobs to be tested, while preventing others from
being performed unnecessarily.

Example:

    def test_hello_job
      assert_performed_jobs 1, only: HelloJob do
        HelloJob.perform_later('jeremy')
        LoggingJob.perform_later
      end
    end

An array may also be specified, to support testing multiple jobs.

Example:

    def test_hello_and_logging_jobs
      assert_nothing_raised do
        assert_performed_jobs 2, only: [HelloJob, LoggingJob] do
          HelloJob.perform_later('jeremy')
          LoggingJob.perform_later('stewie')
          RescueJob.perform_later('david')
        end
      end
    end

Fixes #18802.

Trim space and document :only option.
@perceptec

This comment has been minimized.

Copy link
Contributor Author

perceptec commented Feb 6, 2015

@rafaelfranca Sorry, ok now?

rafaelfranca added a commit that referenced this pull request Feb 6, 2015
Add an `:only` option to `perform_enqueued_jobs` to filter jobs based on type.
@rafaelfranca rafaelfranca merged commit decb7b6 into rails:master Feb 6, 2015
1 check was pending
1 check was pending
continuous-integration/travis-ci The Travis CI build is in progress
Details
@rafaelfranca

This comment has been minimized.

Copy link
Member

rafaelfranca commented Feb 6, 2015

❤️ 💚 💙 💛 💜

@perceptec

This comment has been minimized.

Copy link
Contributor Author

perceptec commented Feb 6, 2015

😄

@perceptec perceptec deleted the perceptec:add_only_performed_option branch Feb 6, 2015
@dhh

This comment has been minimized.

Copy link
Member

dhh commented Feb 6, 2015

Fantastico! Great work.

@perceptec

This comment has been minimized.

Copy link
Contributor Author

perceptec commented Feb 6, 2015

☀️

@morgoth

This comment has been minimized.

Copy link
Member

morgoth commented Feb 6, 2015

Would love to see it backported to 4.2. Can it happen?

@dhh

This comment has been minimized.

Copy link
Member

dhh commented Feb 6, 2015

We aren't back porting features any more. Rails 5 will be here soon though!

On Feb 6, 2015, at 11:55, Wojciech Wnętrzak notifications@github.com wrote:

Would love to see it backported to 4.2. Can it happen?


Reply to this email directly or view it on GitHub.

carlosantoniodasilva added a commit to carlosantoniodasilva/rails that referenced this pull request Feb 8, 2015
@old_perform_enqueued_jobs = queue_adapter.perform_enqueued_jobs
@old_perform_enqueued_at_jobs = queue_adapter.perform_enqueued_at_jobs
queue_adapter.perform_enqueued_jobs = true
queue_adapter.perform_enqueued_at_jobs = true
queue_adapter.filter = only

This comment has been minimized.

Copy link
@jeremy

jeremy Mar 6, 2015

Member

This leaks to subsequent test cases. It needs to be reset back to the original value in the ensure below.

This comment has been minimized.

Copy link
@jeremy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.