require 'spec_helper' describe Workers::ExportUser do before do allow(User).to receive(:find).with(alice.id).and_return(alice) end it 'calls export! on user with given id' do expect(alice).to receive(:perform_export!) Workers::ExportUser.new.perform(alice.id) end it 'sends a success message when the export is successful' do allow(alice).to receive(:export).and_return(OpenStruct.new) expect(ExportMailer).to receive(:export_complete_for).with(alice).and_call_original Workers::ExportUser.new.perform(alice.id) end it 'sends a failure message when the export fails' do allow(alice).to receive(:export).and_return(nil) expect(alice).to receive(:perform_export!).and_return(false) expect(ExportMailer).to receive(:export_failure_for).with(alice).and_call_original Workers::ExportUser.new.perform(alice.id) end end