diff --git a/lib/sidekiq/worker.rb b/lib/sidekiq/worker.rb index c91fff41..ebb87fb9 100644 --- a/lib/sidekiq/worker.rb +++ b/lib/sidekiq/worker.rb @@ -24,6 +24,8 @@ module Sidekiq attr_accessor :jid def self.included(base) + raise ArgumentError, "You cannot include Sidekiq::Worker in an ActiveJob: #{base.name}" if base.ancestors.any? {|c| c.name == 'ActiveJob::Base' } + base.extend(ClassMethods) base.class_attribute :sidekiq_options_hash base.class_attribute :sidekiq_retry_in_block diff --git a/test/test_rails.rb b/test/test_rails.rb new file mode 100644 index 00000000..1a5379f7 --- /dev/null +++ b/test/test_rails.rb @@ -0,0 +1,23 @@ +require_relative 'helper' +require 'sidekiq' +require 'sidekiq/web_helpers' + +$HAS_AJ = true +begin + require 'active_job' +rescue + $NO_AJ = false +end + +class TestRails < Sidekiq::Test + + describe 'ActiveJob' do + it 'does not allow Sidekiq::Worker in AJ::Base classes' do + ex = assert_raises ArgumentError do + c = Class.new(ActiveJob::Base) + c.include Sidekiq::Worker + end + assert_includes ex.message, "cannot include" + end if $HAS_AJ + end +end