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

48 lines
1.4 KiB
Ruby
Raw Normal View History

require 'helper'
require 'sidekiq'
require 'active_record'
require 'action_mailer'
require 'sidekiq/extensions/action_mailer'
require 'sidekiq/extensions/active_record'
Sidekiq.hook_rails!
class TestExtensions < MiniTest::Unit::TestCase
describe 'sidekiq extensions' do
before do
Sidekiq.client_middleware.entries.clear
Sidekiq.instance_variable_set(:@redis, MiniTest::Mock.new)
@redis = Sidekiq.redis
end
class MyModel < ActiveRecord::Base
def self.long_class_method
raise "Should not be called!"
end
end
it 'allows delayed exection of ActiveRecord class methods' do
@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
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
it 'allows delayed delivery of ActionMailer mails' do
@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
end
end
end