mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Merge branch 'master' of github.com:mperham/sidekiq
This commit is contained in:
commit
fb0b09d563
3 changed files with 30 additions and 0 deletions
|
@ -16,6 +16,7 @@ module Sidekiq
|
||||||
:require => '.',
|
:require => '.',
|
||||||
:environment => nil,
|
:environment => nil,
|
||||||
:timeout => 5,
|
:timeout => 5,
|
||||||
|
:enable_rails_extensions => true,
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.options
|
def self.options
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module Sidekiq
|
module Sidekiq
|
||||||
def self.hook_rails!
|
def self.hook_rails!
|
||||||
|
return unless Sidekiq.options[:enable_rails_extensions]
|
||||||
if defined?(ActiveRecord)
|
if defined?(ActiveRecord)
|
||||||
ActiveRecord::Base.extend(Sidekiq::Extensions::ActiveRecord)
|
ActiveRecord::Base.extend(Sidekiq::Extensions::ActiveRecord)
|
||||||
ActiveRecord::Base.send(:include, Sidekiq::Extensions::ActiveRecord)
|
ActiveRecord::Base.send(:include, Sidekiq::Extensions::ActiveRecord)
|
||||||
|
|
28
test/test_extension_configuration.rb
Normal file
28
test/test_extension_configuration.rb
Normal 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 enable_rails_extensions option to true by default' do
|
||||||
|
assert_equal true, Sidekiq.options[:enable_rails_extensions]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should extend ActiveRecord and ActiveMailer if enable_rails_extensions is true' do
|
||||||
|
assert_equal ActionMailer::Base, Sidekiq.hook_rails!
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not extend ActiveRecord and ActiveMailer if enable_rails_extensions is false' do
|
||||||
|
Sidekiq.options = { :enable_rails_extensions => false }
|
||||||
|
assert_equal nil, Sidekiq.hook_rails!
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue