-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We want all of our jobs to use ActiveJob.
- Loading branch information
Showing
5 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
module Betterment | ||
class DirectDelayedEnqueue < Base | ||
DELAY_MESSAGE = 'Please use Active Job instead of using `Object#delay`' | ||
ENQUEUE_MESSAGE = 'Please use Active Job instead of using `Delayed::Job.enqueue`' | ||
|
||
# @!method enqueue?(node) | ||
def_node_matcher :enqueue?, <<-PATTERN | ||
(send (const (const nil? :Delayed) :Job) :enqueue ...) | ||
PATTERN | ||
|
||
def on_send(node) | ||
add_offense(node, message: DELAY_MESSAGE) if node.method?(:delay) | ||
add_offense(node, message: ENQUEUE_MESSAGE) if enqueue?(node) | ||
end | ||
end | ||
end | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
spec/rubocop/cop/betterment/direct_delayed_enqueue_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe RuboCop::Cop::Betterment::DirectDelayedEnqueue, :config do | ||
it "adds an offense when using `.delay` without arguments" do | ||
expect_offense(<<~RUBY) | ||
user.delay.save! | ||
^^^^^^^^^^ Please use Active Job instead of using `Object#delay` | ||
RUBY | ||
end | ||
|
||
it "adds an offense when using `.delay` with arguments" do | ||
expect_offense(<<~RUBY) | ||
user.delay(foo: 'bar').save! | ||
^^^^^^^^^^^^^^^^^^^^^^ Please use Active Job instead of using `Object#delay` | ||
RUBY | ||
end | ||
|
||
it "adds an offense when using `Delayed::Job.enqueue`" do | ||
expect_offense(<<~RUBY) | ||
Delayed::Job.enqueue(Job.new) | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Please use Active Job instead of using `Delayed::Job.enqueue` | ||
RUBY | ||
end | ||
end |