Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 598
John Bachir Avatar asked Dec 08 '10 03:12

John Bachir


2 Answers

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

get '/', {}, { "HTTP_USER_AGENT" => "Googlebot" } 
like image 175
Noé Avatar answered Sep 22 '22 11:09

Noé


None of the above answers worked for me, the following is what finally worked in an rspec controller test:

@request.user_agent = "a MobileDevice/User-Agent" post :endpoint, param: 2354 
like image 31
Alex Pretzlav Avatar answered Sep 18 '22 11:09

Alex Pretzlav