Module: Mobylette::Helmet

Extended by:
ActiveSupport::Concern
Defined in:
lib/mobylette/helmet.rb

Overview

Mobylette::Helmet provides helper methods to help you when testing your controllers for a mobile request.

You must include Mobylette::Helmet into your test case, in the README there is more documentation about how to make this test wide.

Instance Method Summary collapse

Instance Method Details

#force_mobile_request_agent(user_agent = "Android") ⇒ Object

Force the request for the user_agent

Remember to add it BEFORE the request

Example:

it "should render the mobile_device view on mobile request" do
  force_mobile_request_agent("Android")
  get :index
  response.should render_template(:mobile_device)
end

21
22
23
# File 'lib/mobylette/helmet.rb', line 21

def force_mobile_request_agent(user_agent = "Android")
  request.user_agent = user_agent
end

#reset_test_request_agentObject

Reset the user_agent to the default (“Rails Testing”)

Remember to add it BEFORE the request

Example:

it "should render the normal_view view on mobile request" do
  reset_test_request_agent
  get :index
  response.should render_template(:normal_view)
end

36
37
38
# File 'lib/mobylette/helmet.rb', line 36

def reset_test_request_agent
  request.user_agent = "Rails Testing"
end

#set_session_override(value) ⇒ Object

set_session_override will set the 'value' to the session override control value may be:

  • :ignore_mobile -> This will disable mobile checking, and the original format will be rendered

  • :force_mobile -> This will force to all requests for this session be mobile (except xhr)

  • nil -> This will disable session override


45
46
47
# File 'lib/mobylette/helmet.rb', line 45

def set_session_override(value)
  session[:mobylette_override] = value
end