How can I unit test that my JSON API resource callback is been registered as after_create
, and that send_notifications is invoked, and I can expect(MyMailer).to receive(:welcome_email)
?
When I attempt to allow
& expect
MyResource#send_notifications, or MyMailer.welcome_email they calls are not tracked.
class MyResource < BaseResource
after_create :send_notifications
def send_notifications
MyMailer.welcome_email(_model).deliver
end
end
# rspec
RSpec.describe Creem::Jpi::V1::MyResourceResource, type: :resource do
include JsonApiResourceHelpers
let(:my_resource) { create(:my_resource) }
subject { described_class.new(my_resource, {}) }
it { expect(described_class).to be < BaseResource }
describe 'callbacks' do
xit 'how do I unit test my callbacks?'
end
end