1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Add hook_rails configuration option to make the Rails extensions optional

This commit is contained in:
Jon Hinson 2012-03-26 15:37:38 -05:00
parent 2e9e3a5064
commit cd423f9cdc
3 changed files with 30 additions and 0 deletions

View file

@ -16,6 +16,7 @@ module Sidekiq
:require => '.',
:environment => nil,
:timeout => 5,
:hook_rails => true,
}
def self.options

View file

@ -1,5 +1,6 @@
module Sidekiq
def self.hook_rails!
return unless Sidekiq.options[:hook_rails]
if defined?(ActiveRecord)
ActiveRecord::Base.extend(Sidekiq::Extensions::ActiveRecord)
ActiveRecord::Base.send(:include, Sidekiq::Extensions::ActiveRecord)

View file

@ -0,0 +1,28 @@
require 'helper'
require 'sidekiq'
class TestExtensionConfiguration < MiniTest::Unit::TestCase
describe 'sidekiq rails extensions configuration' do
before do
@options = Sidekiq.options
end
after do
Sidekiq.options = @options
end
it 'should set hook_rails option to true by default' do
assert_equal true, Sidekiq.options[:hook_rails]
end
it 'should extend ActiveRecord and ActiveMailer if hook_rails is true' do
assert_equal ActionMailer::Base, Sidekiq.hook_rails!
end
it 'should not extend ActiveRecord and ActiveMailer if hook_rails is false' do
Sidekiq.options = { :hook_rails => false }
assert_equal nil, Sidekiq.hook_rails!
end
end
end