If you find that you get this error in RSpec:
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"].
Then you have to specify this in your spec:
request.env[“HTTP_REFERER”] = “where_i_came_from”
based on this answer in StackOverflow (it of course doesn’t necessarily have to equal “where_i_came_from”). This can happen if you redirect :back in your code.