2012-02-19 00:08:53 -05:00
|
|
|
require 'helper'
|
2012-02-19 16:02:32 -05:00
|
|
|
require 'sidekiq'
|
2012-02-19 00:08:53 -05:00
|
|
|
require 'active_record'
|
|
|
|
require 'action_mailer'
|
2012-02-19 16:02:32 -05:00
|
|
|
require 'sidekiq/extensions/action_mailer'
|
|
|
|
require 'sidekiq/extensions/active_record'
|
|
|
|
|
2012-03-10 15:30:15 -05:00
|
|
|
Sidekiq.hook_rails!
|
2012-02-19 00:08:53 -05:00
|
|
|
|
|
|
|
class TestExtensions < MiniTest::Unit::TestCase
|
|
|
|
describe 'sidekiq extensions' do
|
|
|
|
before do
|
|
|
|
Sidekiq.client_middleware.entries.clear
|
2012-03-01 16:41:12 -05:00
|
|
|
Sidekiq.instance_variable_set(:@redis, MiniTest::Mock.new)
|
|
|
|
@redis = Sidekiq.redis
|
2012-02-19 00:08:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class MyModel < ActiveRecord::Base
|
|
|
|
def self.long_class_method
|
|
|
|
raise "Should not be called!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-19 16:02:32 -05:00
|
|
|
it 'allows delayed exection of ActiveRecord class methods' do
|
2012-02-19 00:08:53 -05:00
|
|
|
@redis.expect(:rpush, @redis, ['queue:default', "{\"class\":\"Sidekiq::Extensions::DelayedModel\",\"args\":[\"---\\n- !ruby/class 'TestExtensions::MyModel'\\n- :long_class_method\\n- []\\n\"]}"])
|
|
|
|
MyModel.delay.long_class_method
|
2012-02-19 00:24:11 -05:00
|
|
|
@redis.verify
|
2012-02-19 00:08:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows delayed exection of ActiveRecord instance methods' do
|
|
|
|
skip('requires a database')
|
|
|
|
end
|
|
|
|
|
|
|
|
class UserMailer < ActionMailer::Base
|
|
|
|
def greetings(a, b)
|
|
|
|
raise "Should not be called!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-19 16:02:32 -05:00
|
|
|
it 'allows delayed delivery of ActionMailer mails' do
|
2012-02-19 00:08:53 -05:00
|
|
|
@redis.expect(:rpush, @redis, ['queue:default', "{\"class\":\"Sidekiq::Extensions::DelayedMailer\",\"args\":[\"---\\n- !ruby/class 'TestExtensions::UserMailer'\\n- :greetings\\n- - 1\\n - 2\\n\"]}"])
|
|
|
|
UserMailer.delay.greetings(1, 2)
|
2012-02-19 00:24:11 -05:00
|
|
|
@redis.verify
|
2012-02-19 00:08:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|