I’m trying to figure out how to run integration tests that are storybased and where AJAX redirects appear during the ‘story’.
Simple login example: I login to the website using
def user.logs_in(email, pwd)
get root_path
assert_response :success
assert_template 'index'
post :post, session_path, :email => email, :pwd => pwd
assert_response :redirect
assert_redirect_to backend_path
follow_redirect!
assert_response :success
assert_template 'index'
assert session[:user_id]
end
Unfortunately the login process is AJAX based and insted of a 301-redirect it returns
document.location.href = "<%= backend_path >";
which gives back a 200-code meaning that
assert_response :redirect
fails.
How can i handle AJAX redirects in my integration tests?
If there is no redirect, of course you won’t be able to (successfully) test for it. So instead test for what you are doing: You want the response to be a
200and the body to be a Javascript snippet. Or just useassert_template, too.If you want to test if your Javascript-Login-Button actually evals the js body and how the browser reacts to that you would have to use something like Selenium.