My Rails app currently has a thumbnail upload endpoint which frequently times out on Heroku due to the 30 second request limit. I use Carrierwave and would like to switch to CarrierWaveDirect to solve the problem by doing direct to S3 uploads.
Before I do so, I would like to write a regression test and see it fail with a request timeout. How can I do that?
Most of my tests are high level Selenium/capybara tests, so I tried writing one which stubs the controller action to always throw a timeout error:
# Simulates 30 second Heroku timeout for thumbnail uploads.
context 'when PATCH requests timeout' do
before do
allow_any_instance_of(Api::V1::VideosController).to receive(:update).and_wrap_original do |m, *args|
if request.content_type == 'multipart/form-data'
raise Net::HTTPRequestTimeOut
else
m.call(*args)
end
end
end
it 'uploads custom thumbnails direct to S3' do
signup_and_verify_email(signup_intent: :seller)
visit_store_via_upload_link
upload_test_video
upload_thumbnail
end
end
This fails because request
is undefined in the context of the block. Before I go further with this, whats the best way to write a test for this scenario?