My test looks (more or less) like this:
subject(:download_attachment) { get :download_attachment, params: { id:
message.id } }
let(:message) { create :message }
it 'redirects to file download link' do
allow_any_instance_of(ActiveStorage::Blob).to receive(:service_url).and_return(service_url)
expect(download_attachment).to redirect_to service_url
end
but I know that `allow_any_instance_of` is discouraged (and deprecated). An alternative is
download_attachment
but this also feels a bit hacky.
Neither method is actually checking that the redirect is to the correct url for the correct attachment so ideally I would like to have `allow(message.attachment.blob).to receive(:service_url).and_return(service_url)`. Obviously this isn't working as the message is getting loaded new in the controller.
Is there a way to do this? Thanks.
Regards,
Joe