JSON API リソースのコールバックが として登録されているafter_create
こと、および send_notifications が呼び出されていることを単体テストするにはどうすればよいexpect(MyMailer).to receive(:welcome_email)
ですか?
allow
& expect
MyResource#send_notifications または MyMailer.welcome_email を実行しようとすると、呼び出しが追跡されません。
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