RSG RSG - 4 months ago 18
Ajax Question

How to add a delay to Rails controller for testing?

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?

RSG RSG
Answer

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.