ruby on rails - Testing unmarshalling of asynchronous ActionMailer methods using Sidekiq -
tldr; how can test poro argument asynchronous actionmailer action (using sidekiq) serializes , deserializes correctly?
sidekiq provides rspec matchers testing job enqueued , performing job (with given arguments).
--
to give context, have ruby on rails 4 application actionmailer. within actionmailer method takes in poro argument - references data need in email. use sidekiq handle background jobs. turns out there issue in deserializing argument fail when sidekiq decided perform job. haven't been able find way test correctness of un/marshaling such poro called action being used when performed.
for example:
given actionmailer action
class applicationmailer < actionmailer::base def send_alert profile @profile = profile mail(to: profile.email) end end
...
i use this
profile = profiledetailsservice.new(user) applicationmailer.send_alert(profile).deliver_later
...
and have test (but fails)
let(:profile) { profiledetailsservice.new(user) } 'request email sent' expect { applicationmailer.send_alert(profile).deliver_later }.to have_enqueued_job.on_queue('mailers') end
any assistance appreciated.
you can test in synchronous way (using irb , without need of start sidekiq workers).
let's worker class has following implementation:
class worker include sidekiq::worker def perform(poro_obj) puts poro_obj.inspect # ... end end
you can open irb (bundle exec irb
) , type following commands:
require 'sidekiq' require 'worker' worker.new.perform
thus, execute code in synchronous way , using sidekiq (note we're invoking perform
method instead of perform_async
).
i think best way debug code.
Comments
Post a Comment