HTTP_REFERER for RSpec is missing

Currently got this error message after executing my RSpec tests:

ActionController::RedirectBackError:
 No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify request.env["HTTP_REFERER"].

The error message and Stackoverflow tells you to set request.env[“HTTP_REFERER”]. I did that:

request.env["HTTP_REFERER"] = "/signin"

But that didn’t helped. Instead of that I set the HTTP_REFERRER directly in the post. Here is the snippet from my test code:

post "/sessions", {:session => {:email => user.email, :password => user.password}}, {"HTTPS" => "on", 'HTTP_REFERER' => '/signin'}

That fixed my problem.

Published by Robert Reiz

CEO @ VersionEye. Passionated software developer since 1998.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: