Is it possible to specify a user agent in a rails integration test or spec?

John Bachir picture John Bachir · Dec 8, 2010 · Viewed 10.2k times · Source

I was doing this before in a rails 2 app in a ActionController::IntegrationTest with

get '/', {}, {:user_agent => "Googlebot"}

but this seems to not work anymore in Rails 3.

What should I do?

Answer

Noé picture Noé · Jan 6, 2011

If you use request.user_agent in your application, you can write the following code:

get '/', {}, { "HTTP_USER_AGENT" => "Googlebot" }