I'm testing the front end of a web application and want to test how some of the transitions appear with various delays in between AJAX requests. Is there any way I can add a sleep(1500)
to my controller to delay the response?
Controller like so:
def catalog
#Makes the request pause 1.5 seconds
sleep 1.5
...
end
Even better: only add the sleep for the dev environment.
Elaborating on accepted answer. If you have some base controller like the default ApplicationController
which is extended by any other controller you may define the following filter:
class ApplicationController < ActionController::Base
# adds 1s delay only if in development env
before_action if: "Rails.env.development?" do
sleep 1
end
end
Where: 1 is number of seconds to wait before returning any response, see sleep docs
This filter will be triggered only if your application is in development environment and it will add desired delay to every request processed by your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With